question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Fallback mode

See original GitHub issue

Description

Fallback mode is an alternative request interception mechanism applied in a browser. Fallback mode is automatically enabled by the library when either of the following conditions is met:

  • The browser doesn’t support the Service Worker API;
  • The user has navigator.cookieEnabled set to false that forbids access to the worker;
  • The application is loaded using the file:// protocol.

Motivation

Fallback mode is aimed at improving the browser support and enabling the library in static builds of various tools (i.e. Storybook).

Statements

  1. Fallback mode is enabled automatically by the library.
  2. There is no way to opt-out of the fallback mode.
  3. There is no way to enable the fallback mode when the worker can be used instead.
  4. Requests intercepted via the fallback mode do not appear in the “Network” tab and don’t actually happen (see technical details).

Technical details

Fallback mode is powered by the recent addition of the fetch and XMLHttpRequest interceptors to the @mswjs/interceptors library. Under the hood, fallback mode patches window.fetch and window.XMLHttpRequest to provision the interception of requests.

Fallback mode is similar to the way most other API mocking solutions work: patching the in-browser request modules. In Mock Service Worker fallback mode will only affect the library’s behavior in the environments where Service Worker API cannot be otherwise used.

Pre-requisites

Public API

There are no changes to the public API related to this feature. Fallback mode is enabled automatically, when necessary.

The only user-facing change would be the change of the library’s activation message:

[MSW] Mocking enabled (fallback-mode).

In addition to the activation message change, the library should print the warning message indicating that the worker couldn’t be registered in the current environment:

[MSW] Cannot register a Service Worker in the current environment. Using the fallback mode instead.

Read more about the fallback mode: <DOCS_LINK>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:20
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
otaciliolacerdacommented, Mar 28, 2021

Hi @kettanaito,

Another condition could be to check navigator.cookieEnabled. I was trying to test a scenario on my app where the cookies where disabled but I could not use the mock service due to the error: The user denied permission to use Service Worker. The fallback mode would be nice on this case.

0reactions
kettanaitocommented, Jun 29, 2022

Hey, @catch99. Yes, you’ve understood correctly. Insecure contexts, such as serving an app over HTTP or an untrusted HTTPS, are where a Service Worker cannot register per spec. Instead of leaving you with a broken state, MSW falls back to a more conventional fetch/XHR patching to still keep the mocking functional.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RFC 7507 - TLS Fallback Signaling Cipher Suite Value (SCSV ...
TLS Fallback Signaling Cipher Suite Value (SCSV) for Preventing Protocol Downgrade Attacks RFC 7507 ; Show Last changed 2015-02-10 · RFC 7507 (Proposed...
Read more >
RFC Callback Whitelist - SAP Blogs
Profile parameter rfc/callback_security_method determines the system behavior: Value 0: Emergency fallback mode: All whitelists are ignored.
Read more >
The Risks of SAP RFC Callbacks and How to Avoid Them
Emergency Mode (fallback) Any callback is allowed. Existing allowlists for RFC callbacks (including entries on active lists) are ignored.
Read more >
RFC 8643: An Opportunistic Approach for Secure Real-time ...
Introduction Opportunistic Security (OS) [RFC7435] is an approach to security that defines a third mode for security between "cleartext" and "comprehensive ...
Read more >
rfc/callback_security_method - SAPBASISINFO
Value 0: Emergency mode (fallback). If the callback is prohibited by the preceding call of the function module RFC_CALLBACK_REJECTED, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found