Skip to content

feat(service-worker): Adds for type in provideServiceWorker #62831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

SkyZeroZx
Copy link
Contributor

feat(service-worker): Add type option to provideServiceWorker

Enables specifying the script type ('classic' or 'module') when registering Service Workers, improving compatibility with ES module features.

The change includes:

  • Added type to SwRegistrationOptions interface
  • Modified service worker registration to pass the type option
  • Added comprehensive unit tests to verify the new functionality
  • Updated existing tests to include the new option

Motivation/Use Cases

The type option is particularly useful for:

  • ES Module support: Enabling ES module features like import/export in service worker scripts
  • Modern JavaScript: Supporting modern JavaScript syntax and module system in service workers
  • Compliance with PWA best practices: Aligning with modern service worker registration standards

Proposed Solution

  • Add type property to the SwRegistrationOptions abstract class
  • Implement property handling in the service worker registration logic
  • Pass the option through to the native navigator.serviceWorker.register() API
  • Maintain full backward compatibility with existing configurations (defaults to 'classic')

Examples of New Usage

Basic configuration with provideServiceWorker

export const appConfig: ApplicationConfig = {
  providers: [
    provideServiceWorker('ngsw-worker.js', {
      enabled: !isDevMode(),
      type: 'module', // Enable ES module features
    }),
  ],
};

@pullapprove pullapprove bot requested a review from AndrewKushnir July 26, 2025 06:03
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: service-worker Issues related to the @angular/service-worker package labels Jul 26, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 26, 2025
Enables specifying the script type ('classic' or 'module') when registering Service Workers, improving compatibility with ES module features.
@SkyZeroZx SkyZeroZx force-pushed the add-service-worker-type branch from 2ec391b to 3b82c3e Compare July 26, 2025 06:05
Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

reviewed-for: fw-general, public-api

@pullapprove pullapprove bot requested review from JeanMeche and kirjs August 6, 2025 11:38
Copy link
Member

@JeanMeche JeanMeche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: public-api

@thePunderWoman thePunderWoman added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release labels Aug 6, 2025
@crisbeto
Copy link
Member

crisbeto commented Aug 6, 2025

This PR was merged into the repository by commit 5220b51.

The changes were merged into the following branches: main

@crisbeto crisbeto closed this in 5220b51 Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: service-worker Issues related to the @angular/service-worker package detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants