简体   繁体   中英

Create an extension for Chrome to just run a background script without user intervention

I'm trying to create a simple extension which run a script without user intervention . Script will automatically create notifications and user has to do nothing but install the extension.

What my background.js looks like,

chrome.alarms.create("myAlarm", {
  periodInMinutes : 1
});

chrome.alarms.onAlarm.addListener(function(alarm) {
  if (alarm.name === "myAlarm") {
    alert("Tick...");
  }
});

So in this case there is no use of a browser action button . Anyway if I remove the below part the extension will not work ( alert with 'Tick' will NOT popup ).

"browser_action": {
"default_icon": "icon.png"}

If I just have like below then there will still be an icon without an image ( ( Anyway alert with 'Tick' will popup )).

"browser_action": {
}

For now what I have is this ( alert with 'Tick' will popup ),

{
  "name": "myExt",
  "version": "1.0",
  "manifest_version": 2,
  "background": {
    "scripts": ["background.js"]
  },
  "browser_action": {
   "default_icon": "icon.png"
  },
  "permissions": [
    "https://www.google.com/",
    "notifications",
    "alarms" 
  ]  
}

All the thing I need to do is in the background.js file. It will use the chrome.alarms to create periodic notifications.

So as all I want is to just run a script in background, Any idea on how to remove that browser action icon from the menu bar ?

Got to know that due to some policies by the Google itself, now only the user is responsible to hide the icon. User who installed the extension can do this by right-clicking and selecting "Hide in Chrome Menu" .

So there is no way to hide the menu icon by the developer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM