How To Wait For Content Script Listener To Load After Background Script Opens Url?
My background script should open an URL and wait for it to load completely, so the content script's listener is ready (Am i right with this?). Then it should send the message 'newU
Solution 1:
In onUpdated callback you need to check if the updated tab is actually the one you've updated manually. However I'd like to suggest a much simpler overall approach:
- remove "content_scripts" section from manifest.json
- run the content script programmatically.
chrome.tabs.update({url: 'https://stackoverflow.com/'}, tab => {
chrome.tabs.executeScript(tab.id, {file: 'content.js'}, ([results]) => {
console.log(results);
});
});
content.js:
// do something// ...............// return some data to executeScript// (only simple types like strings/numbers or arrays/objects consisting of simple types)var results = [...document.links].map(el => el.href);
results;
The last line will transfer the array of URLs to executeScript's callback.
Post a Comment for "How To Wait For Content Script Listener To Load After Background Script Opens Url?"