Lotherad
Lotherad

Reputation: 125

How do I send tab ID at creating?

So I want to create new tab and execute script on new tab and use variables from message sended earlier

chrome.tabs.create({url: myUrlblabla}, function() {
  chrome.tabs.executeScript(null, {file: 'myFileScript.js'}, function(Tab tab) {
    chrome.tabs.sendMessage(tab.id, message.myVariable)
  })
});

And Chrome is saying that there is "unexpected identifier" in this line.

Upvotes: 1

Views: 188

Answers (1)

Fraser Crosbie
Fraser Crosbie

Reputation: 1762

You had a syntax error (Tab tab). Try this code:

chrome.tabs.create({
  url: myUrlblabla
}, function(tab) {
  chrome.tabs.executeScript(tab.id, {
    file: 'myFileScript.js'
  }, function(results) {
    chrome.tabs.sendMessage(tab.id, message.myVariable);
  });
});

Upvotes: 2

Related Questions