From 47c9f0b7b7ae007fb516a2e5fcfd890c9ff01a6b Mon Sep 17 00:00:00 2001 From: Joe Medley Date: Mon, 30 Oct 2023 08:23:09 -0700 Subject: [PATCH] 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. --- .../mv3/getstarted/tut-tabs-manager/index.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/site/en/docs/extensions/mv3/getstarted/tut-tabs-manager/index.md b/site/en/docs/extensions/mv3/getstarted/tut-tabs-manager/index.md index b945ae76682d..ad58c935d75d 100644 --- a/site/en/docs/extensions/mv3/getstarted/tut-tabs-manager/index.md +++ b/site/en/docs/extensions/mv3/getstarted/tut-tabs-manager/index.md @@ -5,7 +5,7 @@ seoTitle: 'Chrome Extensions Tutorial: Manage tabs' subhead: 'Build your first tabs manager.' description: 'Learn how to programmatically organize tabs using tab groups.' date: 2022-10-04 -# updated: 2022-06-13 +updated: 2022-10-30 --- ## Overview {: #overview } @@ -272,12 +272,13 @@ In `popup.js`, add the following code to create a button that will group all the move them into the current window. ```js -... -const button = document.querySelector("button"); -button.addEventListener("click", async () => { +const button = document.querySelector('button'); +button.addEventListener('click', async () => { const tabIds = tabs.map(({ id }) => id); - const group = await chrome.tabs.group({ tabIds }); - await chrome.tabGroups.update(group, { title: "DOCS" }); + if (tabIds.length) { + const group = await chrome.tabs.group({ tabIds }); + await chrome.tabGroups.update(group, { title: 'DOCS' }); + } }); ```