简体   繁体   中英

Background script hosted app chrome

I've serached for a while but cannot find any answer so I'll get right to it: Can i have background scripts running in a hosted chrome app? All i can find is for extensions, but this is an app, not an extensions. And furthermore; if so, can this background script update the appcache in the background without having the user visiting the page to do so?

Update: I've still not found an answer to this. I've read every single word I can find on google regarding this, but all it says is "app". This usually refers to packaged app, and not hosted app. Does anyone have any more input?

Yes, you can. You must have seen Chrome run in the background - you've closed the browser, yet you see the small Chrome icon in the taskbar(or wherever) and there is a process. I can't find any concrete info on how to achieve that though, not on first glance at Google, but i suppose a thourough search will do. And you always have the option to contact Google, they do respond.

As for your second question - yep .

Edit: But, at least on PC&Mac, they can be forcibly closed - link

Edit2: I found an example background App that includes documentation - link

Yes and yes.

I recently threw something like this together for a web game I'm working on.

You can't use Background Scripts specifically though, you have to use the background pages API and your site has to be HTTPS (no plain HTTP allowed).

All of the documentation on hosted apps seem to have been deleted though (I think Google is trying to encourage everyone to migrate over to W3C Manifests and Service Workers instead).

But this works in hosted apps https://developer.chrome.com/extensions/background_pages

There's also a way to do this in JavaScript from a web page but I can't seem to find any documentation on that anywhere either.

Just to share an example manifest for ya

{
"name": "Example Hosted App",
"description": "An example hosted app.",
"version": "0.1",
"app": {
  "browse_urls": [ "http://example.com/", "https://example.com/" ],
  "launch": {
     "container": "tab",
     "web_url": "https://example.com/"
},
  "urls": [ "*://example.com/", "*://*.example.com/" ]
},
"permissions": [
  "background"
],
"background": {
  "page": "https://example.com/background/"
},
"manifest_version": 2,
"offline_enabled": true,
"icons": { "512": "logo.png" }
}

And on https://example.com/background/ (insert your own URL here) you should be able to set an AppCache and even a Service Worker. Background pages in Chrome are basically just full web pages but you don't see them and a few APIs are missing, so Google doesn't appear to have blocked AppCache, Service Workers, Local Storage or IndexedDB.

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