Use messaging instead of getBackgroundPage

This commit is contained in:
Will Bamberg
2018-01-25 17:10:46 -08:00
parent 6377f7952a
commit f50bc509f6
2 changed files with 11 additions and 4 deletions

View File

@@ -2,7 +2,10 @@
var registered = null;
async function register(hosts, code) {
async function registerScript(message) {
let hosts = message.hosts;
let code = message.code;
if (registered) {
registered.unregister();
@@ -15,3 +18,5 @@ async function register(hosts, code) {
});
}
browser.runtime.onMessage.addListener(registerScript);

View File

@@ -9,9 +9,11 @@ const defaultCode = "document.body.innerHTML = '<h1>This page has been eaten<h1>
hostsInput.value = defaultHosts;
codeInput.value = defaultCode;
async function registerScript() {
let background = await browser.runtime.getBackgroundPage();
background.register(hostsInput.value.split(","), codeInput.value)
function registerScript() {
browser.runtime.sendMessage({
hosts: hostsInput.value.split(","),
code: codeInput.value
});
}
document.querySelector("#register").addEventListener('click', registerScript);