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

fix: update autoconsent library to 12.x #2134

Merged
merged 1 commit into from
Jan 2, 2025
Merged

fix: update autoconsent library to 12.x #2134

merged 1 commit into from
Jan 2, 2025

Conversation

smalluban
Copy link
Collaborator

@smalluban smalluban commented Dec 10, 2024

  • The eval message is no longer sent to the background - execution of the scriptlets is done by the Autoconsent class in the content script by the library
  • The library includes a source of the adblocker engine, even though we are not using it. The final size of the content script increased from 89kb to 528kb.
  • From initial testing, the library went much slower in detecting and "clicking" on CMPs—it might be related to the fact that we disable cosmetics, and then those CMPs are not hidden (?).

@smalluban smalluban requested a review from seia-soto December 10, 2024 10:04
@smalluban smalluban added the package CI: create extension packages label Dec 10, 2024
Copy link

@muodov
Copy link

muodov commented Dec 11, 2024

hey @smalluban, a few notes from the autoconsent side:

  • in the next release (this week) we will make sure that the default Autoconsent bundle tree-shakes the adblocker library. So the bundle size should become smaller
  • There were no changes to the eval behaviour: those messages should be sent to the background, unless isMainWorld is truthy (it is not by default). Could you elaborate on what you're seeing there?

Copy link
Member

@seia-soto seia-soto left a comment

Choose a reason for hiding this comment

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

Just like we disabled enableCosmeticRules before, I think it's good to set enableFilterList: false. Then we don't need to take care about change of default in the future. I think everything else is fine.

@smalluban
Copy link
Collaborator Author

smalluban commented Dec 12, 2024

@muodov It looks like you are right. However, I thought that for a simple reason - the build library contains all of the snippets and methods to execute them - mainWorldEval() - why? This is useless, as those snippets are never run by the content script, but because they are referenced by this method, the library contains all of them in the body...

Zrzut ekranu 2024-12-12 o 09 56 05

Moreover, the snippets are not exported by the npm package, so we reference lib/eval-snippets.ts directly in the background, but with the update to 12.x our build system complains:

[commonjs--resolver] Missing "./lib/eval-snippets" specifier in "@duckduckgo/autoconsent" package

@smalluban
Copy link
Collaborator Author

I've found that referencing snippets is our "hack" - #1599 added by @chrmod some time ago.

@sammacbeth @chrmod We had a similar issue with CSP with injecting scriptlets. Can you provide snippets as a main export instead of passing them with a message from the content script? As we have changed that in the above PR?

@muodov
Copy link

muodov commented Dec 12, 2024

@smalluban there is an option isMainWorld, which makes the content script execute snippets directly, without a round trip to the background. This is useful if the content script is injected in the main (not isolated) world, but it may be limited by page csp, depending on how you inject the script.

As for the imports, you can still import anything if you reference the package dir directly. That is, 'node_modules/@duckduckgo/autoconsent/...' instead of '@duckduckgo/autoconsent/...'

I hope it helps!

@smalluban
Copy link
Collaborator Author

smalluban commented Dec 12, 2024

@muodov I would like to avoid that hack at all, as your source might change at any time, or even it should not be distributed with the npm package in the first place.
Can you provide the main export, so that we can import it like this: import { snippets } from '@duckduckgo/autoconsent?

EDIT: this is already in the dist, but just as a variable var snippets = ... - so it is just about adding export ...

@muodov
Copy link

muodov commented Dec 12, 2024

@smalluban it shouldn't be a problem to export snippets. Could you create an issue for this with a summary of your use case?

@smalluban
Copy link
Collaborator Author

Copy link

github-actions bot commented Jan 2, 2025

@smalluban smalluban merged commit 8adfae9 into main Jan 2, 2025
2 checks passed
@smalluban smalluban deleted the npm-autoconsent branch January 2, 2025 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package CI: create extension packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants