chromeworker/example/background.js

27 lines
780 B
JavaScript

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
console.log(sender);
chrome.tabs.executeScript(sender.tab.id, { runAt: "document_end", file: "task.js"}, function (results) {
console.log(results);
})
sendResponse({});
})
// chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
// console.log(request, sender);
// });
chrome.webRequest.onBeforeRequest.addListener(function(details){
if( details.url.startsWith("http://eson.config") ) {
// console.log(details);
var params = new URLSearchParams(details.url)
TaskUrl = params.get("taskurl");
chrome.tabs.remove(details.tabId, function() { });
return {cancel: true};
}
},{'urls':["<all_urls>"]},['blocking']);