0

I get error when some tabs are created and I want to group them. Although
See the // Error part below

....
    var ids = [];
    myconfig.tabs.forEach((tab) => {
      chrome.tabs.create({ url: tab }).then((tt) => {
        ids.push(tt.id);
      });
    });

... // ids:Array - 0: 72, 1: 73 length: 2

  chrome.tabs.group({tabIds:ids}).then((groupId) => { // ERROR : Error handling response: TypeError: Error in invocation of tabs.group(object options, optional function callback): Error at parameter 'options': Error at property 'tabIds': Value did not match any choice.
      gId = groupId;
    });
  }
});

Pls correct me to solve this error, thanks in advance.

Csaba

user647314
  • 323
  • 1
  • 4
  • 13
  • 1
    `chrome.tabs.group({tabIds:ids})` by this point `ids` doesn't have any values in it yet since `ids` is populated asynchronously when your Promises created in your forEach loop resolve – Nick Parsons Dec 11 '21 at 10:38
  • So. although the debugging shows 2 number in the ids array, in the real process its empty (because the async funtion in still not finished yet) ? – user647314 Dec 11 '21 at 13:33
  • 1
    Yeah that's right, you can do `console.log(JSON.stringify(ids))` right above `chrome.tabs.group({tabIds:ids}).then(...)` to see what `ids` really holds at the time of logging it. – Nick Parsons Dec 11 '21 at 13:55

0 Answers0