1

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.

Xan
  • 74,770
  • 16
  • 179
  • 206
Lotherad
  • 115
  • 1
  • 8

1 Answers1

2

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);
  });
});
Fraser Crosbie
  • 1,672
  • 1
  • 12
  • 21
  • The method signature is also wrong. The callback of `chrome.tabs.create` should take an argument "tab"`, and `executeScript` should take `tab.id` instead of `null` (and its callback is invoked with the result of the script, not the tab, so remove `tab` from its callback). – Rob W Dec 19 '15 at 20:21
  • Ok it is working now but I want to understand how it works. So I create a tab and then execute script on new tab and then I send message but what for is "results"? – Lotherad Dec 20 '15 at 18:10
  • http://stackoverflow.com/questions/13166293/about-chrome-tabs-executescript-id-details-callback – Fraser Crosbie Dec 20 '15 at 18:12
  • Yea but why do I need result of the script injected in the new tab? – Lotherad Dec 20 '15 at 18:19
  • You don't need to use it. It is optional. It is the result of the script in every injected frame. Just delete it if you don't need it. – Fraser Crosbie Dec 20 '15 at 18:27