mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
Use messaging instead of getBackgroundPage
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user