Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@angular/service-worker
Advanced tools
@angular/service-worker is an Angular package that provides support for service workers in Angular applications. It allows you to leverage the power of service workers to enable features like offline capabilities, background data synchronization, and push notifications in your Angular applications.
Offline Capabilities
This feature allows your Angular application to work offline by caching resources. The ServiceWorkerModule is registered with the service worker script 'ngsw-worker.js', and it is enabled based on the environment configuration.
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Background Data Synchronization
This feature allows your application to synchronize data in the background. The SwUpdate service is used to check for updates and prompt the user to reload the application when a new version is available.
import { SwUpdate } from '@angular/service-worker';
constructor(private updates: SwUpdate) {
this.updates.available.subscribe(event => {
if (confirm('New version available. Load New Version?')) {
window.location.reload();
}
});
}
Push Notifications
This feature allows your application to receive push notifications. The SwPush service is used to request a subscription to push notifications using a VAPID key.
import { SwPush } from '@angular/service-worker';
constructor(private swPush: SwPush) {
this.swPush.requestSubscription({
serverPublicKey: 'YOUR_PUBLIC_VAPID_KEY'
}).then(subscription => {
// Send subscription to the server
}).catch(err => console.error('Could not subscribe to notifications', err));
}
Workbox is a set of libraries and Node modules that make it easy to cache assets and take full advantage of features used to build Progressive Web Apps. Compared to @angular/service-worker, Workbox provides more flexibility and is framework-agnostic, making it suitable for a wider range of projects beyond Angular.
sw-precache is a library for generating service worker code that precaches resources to make your web app work offline. It is less integrated with specific frameworks like Angular but offers a straightforward way to implement service workers in any web application.
sw-toolbox provides a set of tools for handling network requests with service workers. It is more focused on runtime caching strategies compared to @angular/service-worker, which offers a more comprehensive solution for Angular applications.
The sources for this package are in the main Angular repo. Please file issues and pull requests against that repo.
Usage information and reference details can be found in Angular documentation.
License: MIT
19.0.0-next.0 (2024-08-14)
Errors that are thrown during ApplicationRef.tick
will now be rethrown when using TestBed
. These errors should be
resolved by ensuring the test environment is set up correctly to
complete change detection successfully. There are two alternatives to
catch the errors:
expect(() => TestBed.inject(ApplicationRef).tick()).toThrow()
TestBed
will reject any outstanding ComponentFixture.whenStable
promises. A jasmine test,
for example, could write expectAsync(fixture.whenStable()).toBeRejected()
.As a last resort, you can configure errors to not be rethrown by
setting rethrowApplicationErrors
to false
in TestBed.configureTestingModule
.
Router.errorHandler
property has been removed.
Adding an error handler should be configured in either
withNavigationErrorHandler
with provideRouter
or the errorHandler
property in the extra options of RouterModule.forRoot
. In addition,
the error handler cannot be used to change the return value of the
router navigation promise or prevent it from rejecting. Instead, if you
want to prevent the promise from rejecting, use resolveNavigationPromiseOnError
.Resolve
interface now includes
RedirectCommand
.| Commit | Type | Description | | -- | -- | -- | | 468d3fb9b1 | fix | rethrow errors during ApplicationRef.tick in TestBed (#57200) |
| Commit | Type | Description |
| -- | -- | -- |
| f271021e19 | feat | Add routerOutletData
input to RouterOutlet
directive (#57051) |
| b2790813a6 | fix | Align RouterModule.forRoot errorHandler with provider error handler (#57050) |
| 7436d3180e | fix | Update Resolve interface to include RedirectCommand like ResolveFn (#57309) |
<a name="18.2.0"></a>
FAQs
Angular - service worker tooling!
The npm package @angular/service-worker receives a total of 313,637 weekly downloads. As such, @angular/service-worker popularity was classified as popular.
We found that @angular/service-worker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.