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

HTML Filter doesn't work on service worker requests #2833

Closed
8 tasks done
gunir opened this issue Sep 24, 2023 · 16 comments
Closed
8 tasks done

HTML Filter doesn't work on service worker requests #2833

gunir opened this issue Sep 24, 2023 · 16 comments
Labels
enhancement New feature or request Firefox specific to Firefox fixed issue has been addressed

Comments

@gunir
Copy link

gunir commented Sep 24, 2023

Prerequisites

  • I verified that this is not a filter list issue. Report any issues with filter lists or broken website functionality in the uAssets issue tracker.
  • This is not a support issue or a question. For support, questions, or help, visit /r/uBlockOrigin.
  • I performed a cursory search of the issue tracker to avoid opening a duplicate issue.
  • The issue is not present after disabling uBO in the browser.
  • I checked the documentation to understand that the issue I am reporting is not normal behavior.

I tried to reproduce the issue when...

  • uBO is the only extension.
  • uBO uses default lists and settings.
  • using a new, unmodified browser profile.

Description

HTML Filter is not working as expected, I used a fresh profile, fresh uBlock install, check my reproduce steps.

A specific URL where the issue occurs.

https://voz.vn/

Steps to Reproduce

  • Add this voz.vn##^.p-body-sidebar to My Filter
  • Go to https://voz.vn/
  • Check the right sidebar
  • F5 again
  • The sidebar appear again even if you keep pressing F5:
    image
  • Now press Ctrl+F5, it disappears again:
    image

I've recorded a video, please check it: https://streamable.com/ek1var

Expected behavior

The right sidebar should always get cleaned.

The right sidebar contains many iframes, that's why it's better to remove with HTML Filter ##^ than hiding with Element Hiding ##

I've recorded a video, please check it: https://streamable.com/ek1var

Actual behavior

The right sidebar only disappear if I Ctrl+F5, which is pointless because it's a hard refresh, but it shows up again if I use F5.

I've recorded a video, please check it: https://streamable.com/ek1var

uBO version

1.52.0

Browser name and version

Firefox ESR 115

Operating System and version

Windows 10

@gwarser
Copy link

gwarser commented Sep 24, 2023

Try:

||voz.vn$csp=worker-src 'none'

and unregister service worker from about:serviceworkers.

@gwarser gwarser added the invalid not a uBlock issue label Sep 24, 2023
@gwarser gwarser closed this as completed Sep 24, 2023
@gunir
Copy link
Author

gunir commented Sep 24, 2023

Try:

||voz.vn$csp=worker-src 'none'

and unregister service worker from about:serviceworkers.

Thank you, it worked!

Test video: https://streamable.com/o3ly9l

Should we have a workaround for this issue ?

Header Editor also has this HTML Filtering capability but it doesn't have this issue, it can still modify above webpage even with that serviceworker running.

@stephenhawk8054
Copy link
Member

@gwarser I think we need this https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/filterResponseData#permissions ?

From Firefox 95, to use this API to intercept requests related to the loading of service worker scripts, the "webRequestFilterResponse.serviceWorkerScript" permission is also required.

@uBlock-user
Copy link
Contributor

@gwarser I think we need this https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/filterResponseData#permissions ?

From Firefox 95, to use this API to intercept requests related to the loading of service worker scripts, the "webRequestFilterResponse.serviceWorkerScript" permission is also required.

@gorhill

@gwarser
Copy link

gwarser commented Sep 24, 2023

@stephenhawk8054 uBO filters only main HTML document, does not touch any script or service worker.

@uBlock-user
Copy link
Contributor

What stephenhawk is suggesting is an enhancement if we want to intercept and block web-workers without having to resort to "CSP" filters.

@gwarser
Copy link

gwarser commented Sep 24, 2023

Adding these permissions [to manifest] does not help. Something more need to be done to filter these requests.

@uBlock-user
Copy link
Contributor

Permissions open the way for the enhancement, Obviously, specific code needs to be added to make it happen, hence an enhancement.

@MasterKia MasterKia changed the title HTML Filter behaving wierdly HTML Filter doesn't work on service worker requests Sep 24, 2023
@gunir
Copy link
Author

gunir commented Sep 24, 2023

Adding these permissions [to manifest] does not help. Something more need to be done to filter these requests.

I have a working code for Header Editor addon, I don't know why but it DOES work without manually changing CSP "worker-src", this enhancement will make using/writting HTML Filter more bearable.

This is my code:

Name: VozClean
Modify response body
Regular Expression
^.*?voz.vn/$
Custom function: return val.replace(/<div class="p-body-sidebar">[\s\S]*?<\/footer>/, '<!-- CLEANED -->');

Screenshot:
image

@MasterKia MasterKia added the Firefox specific to Firefox label Sep 24, 2023
@gunir
Copy link
Author

gunir commented Sep 25, 2023

Should we mark this as enhancement and reopen ? It's no longer an issue but improvement is nice.

@gwarser gwarser added something to address something to address and removed invalid not a uBlock issue labels Sep 25, 2023
@gwarser gwarser reopened this Sep 25, 2023
@krystian3w
Copy link

krystian3w commented Sep 26, 2023

A little looks as AdGuard replace, then filter will works only after publish new add-on (if all others ideas fails and uBo add support).

https://adguard.com/kb/general/ad-filtering/create-own-filters/#replace-modifier

I checked on the latest free AdGuard add-on 4.2: it can handle it for Firefox:

||voz.vn^$replace=/<div class="p-body-sidebar">[\s\S]*?<\/footer>/<!-- CLEANED -->/

Unfortunately, AdGuard and their HTML Filtering cannot remove the element without damaging the entire DOM of the website.


I would suggest checking if the add-on "Header Editor" is actually working with action "VozClean" before browser parse HTML.

@gunir
Copy link
Author

gunir commented Sep 27, 2023

Unfortunately, AdGuard and their HTML Filtering cannot remove the element without damaging the entire DOM of the website.

This is very bad imo, but they will fix for sure, they're professional after all.

But well, talking about uBO's HTML Filtering, I don't mind removing worker src manually but it's such a hassle for end-users, HTML Filtering is very beneficial, its actually improve page loading speed by skipping network connections of removed contents entirely.

In this tested, you can see removing vs hiding that sidebar saved a lot of bandwidth:
Removing (116 total requests):
image

Hiding (141 total requests):
image

HTML Filtering is a bit advanced, but I believe it worth our cares to enhance it further to make it more user-friendly.

My 2 cents.

@gorhill gorhill added enhancement New feature or request and removed something to address something to address labels Sep 28, 2023
@gunir
Copy link
Author

gunir commented Oct 6, 2023

I would suggest checking if the add-on "Header Editor" is actually working with action "VozClean" before browser parse HTML.

It does, if you want proof, take this filter: #2833 (comment)

Look at this result pic and check in view-source:
image

Source: https://voz-vn.translate.goog/t/tong-hop-nhung-addon-chat-cho-firefox-pc-mobile.682181/page-315?_x_tr_sl=vi&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp#post-27877026

@krystian3w
Copy link

krystian3w commented Nov 5, 2023

It looks uBo replace gorhill/uBlock@7c3e060c01 have same problem. In AdGuard replace worked fine 2 months ago without kill service worker.

@gorhill
Copy link
Member

gorhill commented Nov 5, 2023

I think this is fixable by giving precedence to content-type when evaluating whether to html-filter a response.

gorhill added a commit to gorhill/uBlock that referenced this issue Nov 6, 2023
@gwarser gwarser added the fixed issue has been addressed label Nov 6, 2023
@gwarser gwarser closed this as completed Nov 6, 2023
@gunir
Copy link
Author

gunir commented Nov 6, 2023

I think this is fixable by giving precedence to content-type when evaluating whether to html-filter a response.

Beautiful and thank you, the recent replace filter loves this fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Firefox specific to Firefox fixed issue has been addressed
Projects
None yet
Development

No branches or pull requests

7 participants