fix: Chrome Extensions service worker host registration (#39290)

This commit is contained in:
Shelley Vohr 2023-08-01 08:04:38 +02:00 committed by GitHub
parent b2c62d6ad1
commit c8f7a0e052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 1 deletions

View file

@ -1 +1,7 @@
console.log('service worker installed');
/* global chrome */
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message === 'fetch-confirmation') {
sendResponse({ message: 'Hello from background.js' });
}
});

View file

@ -0,0 +1,13 @@
/* global chrome */
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
sendResponse(message);
});
window.addEventListener('message', (event) => {
if (event.data === 'fetch-confirmation') {
chrome.runtime.sendMessage('fetch-confirmation', response => {
console.log(JSON.stringify(response));
});
}
}, false);

View file

@ -3,6 +3,17 @@
"description": "Test for extension service worker support.",
"version": "1.0",
"manifest_version": 3,
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"main.js"
],
"run_at": "document_start"
}
],
"background": {
"service_worker": "background.js"
}