When I enable extension for Safari, and first time I tap on the button, it shows me privacy dialog box and when I grant permission, the dialog box is dismissed and to make my extension work, I have to again click on the extension button.
I have requirement that my extension should work only when user taps on the button post enabling the extension. So, for each and every page I visit I need to manually tap on button before my injected content-script comes into action.
My background.js is where extension click method is registered and executes,
Here, from background script, extension button is handled and when tapped, load() from content-script is called via chrome.tabs.sendMessage() and processes different things.
My content-script.js is like,
Here, chrome.runtime.sendMessage() is handled in background script and code in respond() method will be executed.
My query is, are we able to avoid second tap we make on extension button after we granted permission for the extension?
Should permission grant not execute extension button code without explicit tap second time?
I have requirement that my extension should work only when user taps on the button post enabling the extension. So, for each and every page I visit I need to manually tap on button before my injected content-script comes into action.
My background.js is where extension click method is registered and executes,
Code Block chrome.browserAction.onClicked.addListener(function (tab) { getActiveTab(function (tabID) { chrome.tabs.sendMessage(tabID, { name: 'inject-content' }); }); }); function respond(message, sender, callback) { console.log(">>>> PROCESS MESSAGE => " + message); } chrome.runtime.onMessage.addListener(respond);
Here, from background script, extension button is handled and when tapped, load() from content-script is called via chrome.tabs.sendMessage() and processes different things.
My content-script.js is like,
Code Block var loadInit = function loadInit(message, sender, callback) { console.log("SAFARI => " + message.name); if (message.name == 'inject-content') { //chrome.runtime.onMessage.removeListener(loadInit) load(); } }; console.log("SAFARI Message=> "); chrome.runtime.onMessage.addListener(loadInit); function load() { console.log("Loading action methods"); chrome.runtime.sendMessage({ init: true }); }
Here, chrome.runtime.sendMessage() is handled in background script and code in respond() method will be executed.
My query is, are we able to avoid second tap we make on extension button after we granted permission for the extension?
Should permission grant not execute extension button code without explicit tap second time?