简体   繁体   中英

How to load chrome extension background script from remote server?

How can i perform loading chrome extension background script from remote? Is it passible? With eval or something? how to do this, if am hosting the script on remote digital ocean?

DISCLAIMER: Loading background scripts from a remote site is generally NOT recommended, as it gives the remote script a lot of control of the user's browser if not their whole machine.

But if you insist, you could do something like this.

manifest.json

{
  ...
  "background": { "scripts": ["background.js"] },
  "permissions": [ "http://www.yourwebiste.com/*" ],
  ...
}

background.js

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.yourwebiste.com/remotescript.js", false);
xhr.send();
let code = xhr.responseText;
eval(code);

Regardless... DON'T DO THIS ! In the name of security, just don't. Unless you are experienced and understand the caveats, I would whole hardheartedly recommend you don't use this method as it might introduce the execution of foreign code that you might not have control over, ie the remote script.

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