Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
broccoli-serviceworker
Advanced tools
A broccoli plugin automating ServiceWorker file creation for Broccoli and Ember.js
ServiceWorker generator for Broccoli and Ember.js. Derived from broccoli-manifest.
For more details on ServiceWorker check out the following:
ember install broccoli-serviceworker
###Configuration By default the service worker will be generated for production builds and the service worker registration logic will be added to your index.html automatically. If you wish to add your own logic to the generated service worker, you can place that code in .js files in app/serviceworkers. Your code will have full access to Service Worker Toolbox as well as any included tools that you specify with the swIncludeFiles option. Additionally, you can further customize broccoli-serviceworker by setting configurations in your environment.js file:
//app/config/environment.js
ENV.serviceWorker = {
enabled: true,
debug: true,
sourcemaps: true,
precacheURLs: ['/mystaticresource'],
excludePaths: ['test.*', 'robots.txt',],
fallback: [
'/online.html /offline.html'
],
networkFirstURLs: [
'/api/todos'
],
includeRegistration: true,
serviceWorkerFile: "service-worker.js",
skipWaiting: true,
swIncludeFiles: [
'bower_components/pouchdb/dist/pouchdb.js'
],
swEnvironment: {
foo: ENV.foo,
}
};
The following options are available:
{
excludePaths: ['index.html', new RegExp(/.\.map$/)],
}
swEnvironment
variable.####Routing Options The following options allow you to specify routes that use sw-toolbox's built-in handlers. Each of these options accepts an array of URLs that can be strings or regular expressions.
{
route: '/api/todos',
method: 'any',
options: {
origin: 'https://api.example.com'
}
}
####Hooks
The following hooks are available to your service worker code. Implement a hook by defining a function
by the hook's name and it will be called.
brocswPostDeleteCacheHook(cacheName)
-- When a new version of the service worker is loaded, old caches are automatically deleted. This hook is called for each stale cache right after it has been deleted. This hook must return a Promise
.npm install --save broccoli-serviceworker
Use broccoli-serviceworker
as your last filter in the Brocfile.js
like this
var writeServiceWorker = require('broccoli-serviceworker');
...
var completeTree = mergeTrees([appJs, appCss, publicFiles]);
module.exports = mergeTrees([completeTree, writeServiceWorker((completeTree)]);
Upgrade your index.html
(see below) and you are done.
You can the options specified above as the second argument to writeServiceWorker
:
writeServiceWorker(completeTree, {
serviceWorkerFile: "service-worker.js",
excludePaths: ['test.*', 'online.html',],
precacheURLs: ['/api/offlineStates'],
fallback: [
'/api/states /api/offlineStates'
],
networkFirstURLs: [
'/api/todos'
],
skipWaiting: true
});
One additional option is available for usage with Broccoli.js:
In order to use the generated serviceworker, you will need to register the serviceworker. This is done automatically if using as an Ember.js addon. If you're not using Ember.js, you can use the following code:
<!DOCTYPE html>
<html>
...
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./service-worker.js', {scope: './'})
.catch(function(error) {
alert('Error registering service worker:'+error);
});
} else {
alert('service worker not supported');
}
</script>
</html>
FAQs
A broccoli plugin automating ServiceWorker file creation for Broccoli and Ember.js
We found that broccoli-serviceworker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.