Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit 47c9f0b

Browse files
authored
Make sure there are tabs before manipulating them.
Addresses #7601 @AmySteam This seems like a reasonable addition to this code sample. You probably wouldn't be trying to run it unless you had tabs open to documentation, but it's also probably easy to overlook. How many hours have we all wasted because silly minor thing we need to do. This is already in the related sample.
1 parent f3b2245 commit 47c9f0b

File tree

1 file changed

+7
-6
lines changed
  • site/en/docs/extensions/mv3/getstarted/tut-tabs-manager

1 file changed

+7
-6
lines changed

site/en/docs/extensions/mv3/getstarted/tut-tabs-manager/index.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ seoTitle: 'Chrome Extensions Tutorial: Manage tabs'
55
subhead: 'Build your first tabs manager.'
66
description: 'Learn how to programmatically organize tabs using tab groups.'
77
date: 2022-10-04
8-
# updated: 2022-06-13
8+
updated: 2022-10-30
99
---
1010

1111
## Overview {: #overview }
@@ -272,12 +272,13 @@ In `popup.js`, add the following code to create a button that will group all the
272272
move them into the current window.
273273

274274
```js
275-
...
276-
const button = document.querySelector("button");
277-
button.addEventListener("click", async () => {
275+
const button = document.querySelector('button');
276+
button.addEventListener('click', async () => {
278277
const tabIds = tabs.map(({ id }) => id);
279-
const group = await chrome.tabs.group({ tabIds });
280-
await chrome.tabGroups.update(group, { title: "DOCS" });
278+
if (tabIds.length) {
279+
const group = await chrome.tabs.group({ tabIds });
280+
await chrome.tabGroups.update(group, { title: 'DOCS' });
281+
}
281282
});
282283
```
283284

0 commit comments

Comments
 (0)