By default, the Pushwoosh Web SDK expects the pushwoosh-service-worker.js
and pushwoosh-manifest.json
files to be located in the top-level root directory of your website (e.g., https://yourwebsite.com/pushwoosh-service-worker.js
). This is necessary for the service worker to function correctly due to scope limitations.
If you need to place the service worker file in a different location (e.g., a subdirectory like /vendor/
), you must specify its path during the SDK initialization using the serviceWorkerUrl
parameter.
Here's an example of how to initialize the SDK with a custom service worker path:
const Pushwoosh = PushwooshSDK.initialize({
logLevel: 'info',
applicationCode: 'XXXXX-XXXXX', // Your Pushwoosh Application Code
safariWebsitePushId: 'web.com.example.domain', // Your Safari Web Push ID
defaultNotificationTitle: 'Pushwoosh',
defaultNotificationImage: 'https://yourwebsite.com/img/logo-medium.png',
autoSubscribe: false, // We recommend false & using a custom prompt
serviceWorkerUrl: '/path/to/your/pushwoosh-service-worker.js' // Specify the correct path here
});
// Example: Trigger subscription after user interaction
document.getElementById('subscribe-button').addEventListener('click', () => {
Pushwoosh.subscribe();
});
Important Considerations:
-
Specify the Path: Ensure the path provided in
serviceWorkerUrl
correctly points to the location of yourpushwoosh-service-worker.js
file relative to your website's root. - SDK Initialization: Make sure the Pushwoosh SDK initialization script itself is correctly included and executed in your web application.
-
Subscription Prompt: Using
autoSubscribe: true
might not always trigger the prompt due to browser restrictions. It's generally recommended to setautoSubscribe: false
and trigger thePushwoosh.subscribe()
method based on explicit user interaction (e.g., clicking a subscribe button), potentially using a custom subscription prompt. -
Manifest File: While the service worker location can be configured, the
pushwoosh-manifest.json
file generally still needs to be accessible, often from the root or configured appropriately depending on your setup.
Comments
0 comments
Please sign in to leave a comment.