browser.windows.create({ url: "google.com", }, function (window) { var tabid = window.tabs[0].id; var makeItGreen = 'document.body.style.border = "20px solid green"'; browser.tabs.executeScript( tabid, { code: makeItGreen }); 

The code does not want to work, stops at opening the window, and if you run the same code in the console, but divide it into 2 parts, everything works out, if I understand correctly, this is because the callback starts to run when the window itself opens, but the tab is still not loaded, but then the question arises how to execute the code after the tab has loaded.

    2 answers 2

    You understand everything correctly. After opening the tab, you must wait until it is fully loaded. This will help the event browser.tabs.onUpdated .

    The tactic is this: when you create a tab, you memorize its ID and then listen for the event of the full loading of all tabs using onUpdated. As soon as the ID matches, execute the code.

     // createdTabId - ID вкладки, созданой с помощью browser.windows.create browser.tabs.onUpdated.addListener(function(tabId, changeInfo) { if(changeInfo.status === 'complete' && tabId === createdTabId) { // browser.tabs.executeScript } }) 
       <script> win = window.open("http://google.com"); win.opener.addEventListener('load', function (event) { console.log(win); //Окно окна console.log(event); //Объект события console.log(win.document); //Но доступа у вас не будет }); </script>