- From: karthik-mmt <notifications@github.com>
- Date: Thu, 12 Sep 2024 00:55:44 -0700
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/ServiceWorker/issues/1595/2345526088@github.com>
@jakearchibald I am facing an issue with importing a local Firebase CDN file in the service worker (background.js) file. I can't seem to load other scripts or files locally from one file to another. Is there any way to achieve this?
I have tried importScripts, import, injectScripts, and using URLs, but none of these approaches seem to work.
file structure
firebase-app.js
background.js
`// Import necessary Firebase modules
import { initializeApp } from './firebase/firebase-app.js';
import { getMessaging, getToken } from './firebase/firebase-messaging.js';
// Firebase configuration object
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_PROJECT_ID.appspot.com",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize Firebase Cloud Messaging and request permission to get the token
const messaging = getMessaging(app);
// Request for Notification Permission and Get Registration Token
const getRegistrationToken = async () => {
try {
// Ask the user for permission to display notifications
const token = await getToken(messaging, { vapidKey: 'YOUR_PUBLIC_VAPID_KEY' }); // Provide your VAPID key
if (token) {
console.log('Registration Token:', token); // Token that can be used to send notifications
} else {
console.log('No registration token available. Request permission to generate one.');
}
} catch (error) {
console.error('An error occurred while retrieving the token:', error);
}
};
// Call the function to get the registration token
getRegistrationToken();
`
manifest.json
`{
"name": "Test Suite",
"version": "1.0.1",
"manifest_version": 3,
"description": "This extension checks if the site being visited is harmful",
"background": {
"service_worker": "background.js",
"type": "module"
},
"permissions": [
"background",
"gcm",
"tabs",
"notifications",
"storage",
"contextMenus",
"declarativeNetRequest",
"scripting",
"activeTab"
],
"icons": {
"16": "icons/Icon(16X16).png",
"48": "icons/Icon(48X48).png",
"128": "icons/Icon(128X128).png"
},
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'"
},
"action": {
"default_icon": {
"16": "icons/Icon(16X16).png",
"48": "icons/Icon(48X48).png",
"128": "icons/Icon(128X128).png"
},
"default_popup": "popup.html"
}
}
`
{
"name": "Test Suite",
"version": "1.0.1",
"manifest_version": 3,
"description": "This extension checks if the site being visited is harmful",
"background": {
"service_worker": "background.js",
"type": "module"
},
"permissions": [
"background",
"gcm",
"tabs",
"notifications",
"storage",
"contextMenus",
"declarativeNetRequest",
"scripting",
"activeTab"
],
"icons": {
"16": "icons/Icon(16X16).png",
"48": "icons/Icon(48X48).png",
"128": "icons/Icon(128X128).png"
},
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'"
},
"action": {
"default_icon": {
"16": "icons/Icon(16X16).png",
"48": "icons/Icon(48X48).png",
"128": "icons/Icon(128X128).png"
},
"default_popup": "popup.html"
}
}
--
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1595#issuecomment-2345526088
You are receiving this because you are subscribed to this thread.
Message ID: <w3c/ServiceWorker/issues/1595/2345526088@github.com>
Received on Thursday, 12 September 2024 07:55:48 UTC