0

I have a chrome extension and, I'm creating a new tab from my background script this way :

chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
  if (message.todo == "NewTab") {
    var creating = chrome.tabs.create({
      url:message.url,
      active:true
    },function(tab){
      sendResponse({access: "yes"});
    });    
    creating.then(onCreated, onError);
  }  
  return creating;  
});

Is it possible to set the localStorage of the new tab just after creating it ?

  • [Pass data or modify extension html in a new tab/window](https://stackoverflow.com/a/54715122) – wOxxOm Apr 20 '21 at 17:47
  • @wOxxOm the thing is that I'm passing the new tab url from my react app to my content script after a form being submitted and then from my content to my background script. I'm creating the url, but I don't know how to set its localstorage. – marwen ericsson Apr 20 '21 at 17:56
  • So you open a web URL not an extension page in the new tab? In that case you'll need to set localStorage in your content script that matches the new URL. You can use chrome.runtime messaging or chrome.storage to pass the data. – wOxxOm Apr 20 '21 at 18:09
  • @wOxxOm Yes a web URL. I tried passing the data through chrome messaging just after calling the promise called creating but it didn't work. – marwen ericsson Apr 20 '21 at 18:39
  • The content scripts take some time to start even if you declare them with `document_start` so a solution would be to reverse the direction of messaging and ask for the data from your content script. Another approach is [passing the data via cookies](https://stackoverflow.com/a/45105934). – wOxxOm Apr 21 '21 at 02:26

0 Answers0