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

Make sure there are tabs before manipulating them. #7688

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions site/en/docs/extensions/mv3/getstarted/tut-tabs-manager/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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' });
}
});
```

Expand Down
Loading