Skip to content
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

Proposal: webRequest worklets #461

Open
nir-walkme opened this issue Oct 1, 2023 · 5 comments
Open

Proposal: webRequest worklets #461

nir-walkme opened this issue Oct 1, 2023 · 5 comments
Labels
opposed: firefox Opposed by Firefox opposed: safari Opposed by Safari proposal Proposal for a change or new feature

Comments

@nir-walkme
Copy link

It has been discussed many times that DNR does not support many use cases that were possible using Blocking webRequest. Some of the use cases are summarized in this meta ticket.

Some solutions were suggested by the browser vendors, but they are far from achieving reasonable functionality. The fact that DNR is declarative, limits its functionality and any solution based on it would probably be too limited.

Therefore I would like to suggest a non-declarative alternative to DNR and Blocking webRequest. I call it "webRequest worklets".

"webRequest worklets" would provide the benefits of DNR: security and performance, but with lower impact to developers.

How it works?

  • In a similar way to blocking webRequest's addListener API, it is possible to register a worklet to listen to web requests.
  • For more information about Worklets, read here.
  • The Worklets would work in a similar way to the blocking webrequest callbacks and will use code to evaluate and modify web requests (as opposed to using declarative rules).
  • But the worklets would be limited in their functionality. Functionality such as performing network requests or saving to storage would be blocked. It is expected that the Worklets would perform mostly string reading and string manipulation. The Worklet might read information from storage (for example: ad-blocker configuration) but not store it.
  • A similar concept exists today in "Shared Storage", which is using Worklets that are limited in functionality and this way can preserve privacy but still provide important functionality.

Benefits of "webRequest worklets":

  • Security and Privacy - Since the worklets cannot output data externally (not through network nor storage), the traffic that goes through the worklet is kept private and secure.
  • Performance - The fact that the worklet functionality is limited can prevent usage of non-performant code. Moreover, worklets can support WebAssembly or possibly can be pre-compiled so performance is better.
  • Supports most of the use cases that were possible using Blocking webRequest.

Happy to hear your thoughts on this.

@nir-walkme
Copy link
Author

@Celsius273 @hackademix @carlosjeurissen @ghostwords
Happy to hear your thoughts on my proposal

@tophf
Copy link

tophf commented Oct 1, 2023

Standard JS isn't the best choice for a worklet language probably as it's too flexible, it also has tons of built-in globals in globalThis that take time to initialize even with V8 snapshot technique, its interpreter is big as well.

The usual choice for this task is something lua-based like LuaJIT or eLua, which consume ~1000 times less memory and are much faster to start, their interpreter is much smaller and simpler and the JIT version is very performant.

@xeenon xeenon added proposal Proposal for a change or new feature and removed needs-triage labels Oct 3, 2023
@ghostwords
Copy link

Sounds like this would solve #302.

@nir-walkme
Copy link
Author

The usual choice for this task is something lua-based like LuaJIT or eLua, which consume ~1000 times less memory and are much faster to start, their interpreter is much smaller and simpler and the JIT version is very performant.

Thanks for the suggestion.
Is any lua-based language currently being used in browsers?

@tophf
Copy link

tophf commented Oct 8, 2023

AFAIK none, because browser makers don't have worklets in a core performance-critical path, the currently existing use cases (audio processing or the Houdini project) have comparatively lax performance/memory restrictions.

@xeenon xeenon added the opposed: safari Opposed by Safari label Oct 12, 2023
@Rob--W Rob--W added the opposed: firefox Opposed by Firefox label Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
opposed: firefox Opposed by Firefox opposed: safari Opposed by Safari proposal Proposal for a change or new feature
Projects
None yet
Development

No branches or pull requests

5 participants