chrome.tabs.onActivated.addListener(function (activeInfo, something) { chrome.tabs.sendMessage(activeInfo.tabId, {mode: "check"}, function (response) { if (response) { console.log("Already there"); injected = true; } else { injected = false; console.log("Not there, inject contentscript"); } });});
chrome.runtime.onInstalled.addListener((details) => { const currentVersion = chrome.runtime.getManifest().version const previousVersion = details.previousVersion const reason = details.reason Notification.requestPermission(); console.log('Previous Version: ${previousVersion }') console.log('Current Version: ${currentVersion }') chrome.browserAction.setPopup({popup: "index.html"});
switch (reason) { case 'install': console.log('New User installed the extension.')
break; case 'update': console.log('User has updated their extension.') break; case 'chrome_update': case 'shared_module_update': default: console.log('Other install events within the browser') break; }})chrome.runtime.onMessage.addListener( function (request, sender, sendResponse) { if (request.mode == "check") { sendResponse({message: "hi"}); } if (request.mode == "toggle") { toggle(); } });{ "name": "xx", "version": "1.0.10", "short_name": "xx", "description": "xx", "author": "xx", "permissions": [ "notifications", "tabs" ], "icons": { "16": "assets/icons/icon16.png", "48": "assets/icons/icon48.png", "128": "assets/icons/icon128.png" }, "background": { "scripts":["background.js"], "persistent": true }, "content_scripts": [{ "run_at": "document_end", "matches": [ "https://*/*", "http://*/*" ], "js": ["content_script.js"] }], "browser_action": { "default_title": "xx", "default_icon": "xx" }, "web_accessible_resources": [ "index.html" ], "manifest_version": 2, "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"}
chrome.tabs.sendMessage(activeInfo.tabId, {mode: 'check'}, response => { });