brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.87k stars 2.34k forks source link

declarativeNetRequest Rules don't get added on browser launch #30854

Closed ericplane closed 10 months ago

ericplane commented 1 year ago

Description

Whenever using a chrome extension which adds declarativeNetRequest rules it will only work after reloading the extension after browser startup. Brave doesn't check for these rules on browser startup so I need to reload the extension to get it to work allowing the content security policies rather than blocking them.

Steps to Reproduce

  1. Have a Chrome Extension which uses declarativeNetRequests (Manifest v3)
  2. Restart your browser
  3. You will now see that whatever that extension was adding to a website is not getting added until you reload that extension. (Just shows content-security-policy errors in Console)

Reproduces how often:

Easily reproduced

Brave version (brave://version info)

1.52.119 Chromium: 114.0.5735.90 (Official Build) (64-bit)

Other Additional Information:

rebron commented 1 year ago

@ericplaneRBLX Do you have a pointer to an extension that we can look at?

ericplane commented 1 year ago

@rebron The extension I used to find out about this issue is a subscription based extension so I don't really. The only thing I could offer is screensharing the issue and such via Discord.

ericplane commented 1 year ago

The issue only appears in exensions with Manifest v3 and when using the declarativenetrequest feature of the manifest linking it to a json table with all the rules works fine but when you restart your browser you get content-security policy errors and all the svgs don't load from a third-party website but everything else works.

papegaaij commented 1 year ago

Users from our extension report this same issue. The code that registers the rules is not very complicated. It is placed in the main body of the service worker script and looks like this:

if (chrome.declarativeNetRequest) {
    chrome.runtime.onInstalled.addListener((details) => {
        const RULES = [ ... ];
        chrome.declarativeNetRequest.updateDynamicRules({
            removeRuleIds: RULES.map(r => r.id),
            addRules: RULES,
        });
    });
}
nrothGIT commented 1 year ago

Hey we think we're maybe seeing a related/the same issue:

We've a simple brave/chrome extension (for you.com) that basically lets the user toggle their default search engine preferences via extension. The gist of the code is below, but basically a user can send a message for a couple different things and the rulesets (which redirect your default search to the appropriate endpoint) are set below.

} else if (req === "code") {
    chrome.declarativeNetRequest.updateEnabledRulesets({
      enableRulesetIds: ["ruleset_1"],
      disableRulesetIds: ["ruleset_2", "ruleset_3", "ruleset_4"],
    });
    chrome.tabs.create({ url: "https://code.you.com/" });
  } else if (req === "youchat") {
    chrome.declarativeNetRequest.updateEnabledRulesets({
      enableRulesetIds: ["ruleset_3"],
      disableRulesetIds: ["ruleset_1", "ruleset_2", "ruleset_4"],
    });
    chrome.tabs.create({
      url: "https://you.com/search?q=" + queries[index] + "&tbm=youchat",
    });
  }

We think this was working fine until quite recently, but now is a no-op, in that rulesets don't seem to get changed despite message going through. This still works on slightly older versions of Brave (haven't pinned down exact breaking point yet) so seems perhaps related to a recent change? it continues to work fine on Edge/Chrome.

If it helps, the code/published extension is here with that pinned commit:

https://github.com/You-OpenSource/You-Chrome-Extension/blob/e61ddc713217098f752eeafe2883ccee8fd00c7b/public/background.js

Thanks so much for all you do, Brave is great!

gs256 commented 1 year ago

I had the same issue and I created a simple extension to reproduce the bug: https://github.com/gs256/brave-declarativeNetRequest-bug.

The extension should block all images on https://www.google.com/search?q=test&tbm=isch&gbv=1 but it stops working after Brave restart. Reproduction steps are described in my repo.

Here is the whole code:

manifest.json

{
    "name": "Brave extension bug",
    "version": "0.1",
    "manifest_version": 3,
    "background": {},
    "permissions": ["webRequest", "declarativeNetRequest", "declarativeNetRequestFeedback"],
    "declarative_net_request": {
        "rule_resources": [
            {
                "id": "rules",
                "enabled": true,
                "path": "rules.json"
            }
        ]
    },
    "host_permissions": ["*://*/*"],
    "action": {}
}

rules.json

[
    {
        "id": 1,
        "priority": 1,
        "action": {
            "type": "block"
        },
        "condition": {
            "urlFilter": "https://*.gstatic.com/*"
        }
    }
]
andrzejgrzelak commented 1 year ago

@rebron I just linked an issue to a simple extension that is not working because of this bug.

kokofixcomputers commented 1 year ago

@ericplaneRBLX Do you have a pointer to an extension that we can look at?

You can try scratch addons just get some messages on your scratch account then open scratch addons then try to mark messages as read. It works on Chrome but not on Brave

ericplane commented 1 year ago

@rebron Any update on this? It's been almost 3 months and it's a big issue when owning an extension.

Kulsgam commented 1 year ago

I found a temporary hack which can solve this. In the manifest specify a content script, which sends a certain message "x" to the background script. Then for that message run chrome.runtime.reload().

haozi commented 1 year ago

I found a temporary hack which can solve this. In the manifest specify a content script, which sends a certain message "x" to the background script. Then for that message run chrome.runtime.reload().

But, how do it only once?

Kulsgam commented 1 year ago

I found a temporary hack which can solve this. In the manifest specify a content script, which sends a certain message "x" to the background script. Then for that message run chrome.runtime.reload().

But, how do it only once?

Mind clarifying what you mean by once? If you want an example you can check out the source code of the extension I made

pietervanheijningen commented 1 year ago

Would really appreciate a fix by now. My extension with 30k+ users has not been working in brave now for months because of this: https://github.com/pietervanheijningen/clickbait-remover-for-youtube/issues/56

Really don't think brave should deviate much from standard chromium behaviour. Especially with the extension API. Sure this might be a strange way of doing things, but I don't feel like re-writing most of my extension just to make it work for a small minority of brave users.

sharkiller commented 1 year ago

how is this not solved yet? its breaking so many manifest v3 extensions that use declarativeNetRequest.

static rules in brave is working the same as session rules, that get removed on a browser restart. static rules should be always active.

i dont know why they ask for "more info" when is so easy to reproduce.

komprimiert commented 1 year ago

I found a temporary hack which can solve this. In the manifest specify a content script, which sends a certain message "x" to the background script. Then for that message run chrome.runtime.reload().

this assumes that you have access to the extension right? because the extension I use isn't made by me

Kulsgam commented 1 year ago

I found a temporary hack which can solve this. In the manifest specify a content script, which sends a certain message "x" to the background script. Then for that message run chrome.runtime.reload().

this assumes that you have access to the extension right? because the extension I use isn't made by me

Yes, it can only be used for extensions you are developing. If that extension isn't by you, maybe you can contact the developer or even mod the extension to support it for brave. Or just wait until brave fixes this (spoiler - it's probably after GTA 6 gets released)

jslay88 commented 1 year ago

Here is a repo that is an interactive extension just for this repro

I have had this issue on both Linux (arch) and Windows, so I don't think it is OS specific. I would expect it to be a problem on MacOS as well.

Last release this worked was v1.51.118

carl-jin commented 1 year ago

Due to this issue, several of my extensions are unable to function properly, and I have received continuous 1-star ratings over the past week. This has caused significant harm to me. If you are willing to fix this problem, I am willing to generously pay a sum of money.

kokofixcomputers commented 1 year ago

I found a temporary hack which can solve this. In the manifest specify a content script, which sends a certain message "x" to the background script. Then for that message run chrome.runtime.reload().

this assumes that you have access to the extension right? because the extension I use isn't made by me

No... You don't need to write the extension yourself. Here is what i did based on the instructions to temporary resolve this:

Method 1:

  1. Click the more button at the top-right

  2. Click the extensions button

  3. locate the extension that is having problems and click details (in my case ScratchAddons)

    image
  4. Click the background process or if you only have one process click it (shown in the picture)

    image
  5. a new window should open up, click console (shown in the picture)

    image
  6. type in chrome.runtime.reload() and press enter

    image
  7. Try using the extension again.

Method 2:

  1. Click the more button at the top-right
  2. Click the extensions button
  3. locate the extension that is having problems and click details (in my case ScratchAddons) and turn off and turn on image

Method 3:

  1. Click the more button at the top-right
  2. Go to More Tools > Task Manager
  3. A new window will open, scroll down, and click the extension that is having problems
image
  1. Click end process

    image
  2. There will be a message click to message to reload

image
komprimiert commented 1 year ago

@kokofixcomputers That seems like a good solution; unfortunately there isn't anything at all at inspect views for me.

jslay88 commented 1 year ago

This is no different than just flipping the toggle switch off and on, on the extension itself…

On Tue, Oct 24, 2023 at 17:18 kokofixcomputers @.***> wrote:

I found a temporary hack which can solve this. In the manifest specify a content script, which sends a certain message "x" to the background script. Then for that message run chrome.runtime.reload().

this assumes that you have access to the extension right? because the extension I use isn't made by me

No... You don't need to write the extension yourself. Here is what i did based on the instructions to temporary resolve this:

  1. Click the more button at the top-right
  2. Click the extensions button
  3. locate the extension that is having problems and click details (in my case ScratchAddons)

[image: image] https://user-images.githubusercontent.com/113046561/277830253-69a0b01a-d814-4110-9688-8ae75863a035.png

  1. Click the background process or if you only have one process click it (shown in the picture)

[image: image] https://user-images.githubusercontent.com/113046561/277829078-16ea51f0-3030-4e1b-a458-c234dcea6fa6.png

  1. a new window should open up, click console (shown in the picture)

[image: image] https://user-images.githubusercontent.com/113046561/277829317-843141bb-9b21-4962-b2a0-3c048768f415.png

  1. type in chrome.runtime.reload() and press enter [image: image] https://user-images.githubusercontent.com/113046561/277830437-a3af0859-73f4-49ce-9099-fcfac1baa3b5.png
  2. Try using the extension again.

— Reply to this email directly, view it on GitHub https://github.com/brave/brave-browser/issues/30854#issuecomment-1778205233, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABO7UUIYHWON62PZA65HZTLYBBEGHAVCNFSM6AAAAAAY4KMTUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZYGIYDKMRTGM . You are receiving this because you commented.Message ID: @.***>

jslay88 commented 1 year ago

@rebron I think there has been more than enough information collected within this issue to start triage. Can we please get the needs-more-info label removed and get the priority bumped?

komprimiert commented 1 year ago

@kokofixcomputers I mean as mentioned method 2 works for me though but yes: image

kokofixcomputers commented 1 year ago

@kokofixcomputers I mean as mentioned method 2 works for me though but yes: image

Oh yes, I can see that there is no inspect views, sometimes when i open the extension popup and reload the extension details page you will see the inspect views. But... if method 2 works then you problobly don't have to worry about it

Kulsgam commented 1 year ago

Due to this issue, several of my extensions are unable to function properly, and I have received continuous 1-star ratings over the past week. This has caused significant harm to me. If you are willing to fix this problem, I am willing to generously pay a sum of money.

@carl-jin just use what I found -> https://github.com/brave/brave-browser/issues/30854#issuecomment-1685247036 and https://github.com/brave/brave-browser/issues/30854#issuecomment-1696642903

ghost commented 1 year ago

Hi @bbondy,

Can Brave team take a look at this and give some priority to it? As you can see there is enough information to reproduce this, but basically any extension with declarativeNetRequest will not work on start, so extensions have to be disabled and then re-enable for them to work, something not good for any user or even developers since they get people making issues for their extensions for something Brave is 100% at fault.

This issue started happening when Brave got Chromium 114 with build Nightly v1.53.43 (Chromium 114.0.5735.26) on May 16th, the previous version Nightly v1.53.42 (Chromium 113.0.5672.92) on May 15th worked fine with Manifestv3-declarativeNetRequest extensions.

So, it's been 175 days or 5 months 22 days since this started happening, almost half a year where many extensions have failed to work properly as they should. And while Google delayed the force of the Manifestv3, developers are and will adopt it more and more since it is the future, this is limiting Brave as a browser because extensions are important for many users, so Brave should make sure to work work the best it can, without issues like this. Thank you.

sharkiller commented 1 year ago

Due to this issue, several of my extensions are unable to function properly, and I have received continuous 1-star ratings over the past week. This has caused significant harm to me. If you are willing to fix this problem, I am willing to generously pay a sum of money.

@carl-jin just use what I found -> #30854 (comment) and #30854 (comment)

thats not a fix, and thats not even work when you do redirects. thats only work for injected code on pages. declarativeNetRequest do much more than just inject things in pages. they can edit headers, blocks, redirects...

bsclifton commented 1 year ago

Hi folks!

Thanks for the loads of good information! Since we have enough info here, I've cleaned up the comments a bit. Thanks to those that shared information, repro steps, and screenshots. We'll work on getting this prioritized

I've assigned a P3 for now - stay tuned for updates. I'll unlock this again after things cool down a bit

goodov commented 10 months ago

Hey everyone! This is now fixed in nightly starting with version 1.63.94. After some testing we might uplift it into beta/release channels.

goodov commented 10 months ago

Test case:

  1. Install https://chromewebstore.google.com/detail/clickbait-remover-for-you/omoinegiohhgbikclijaniebjpkeopip
  2. Ensure it works on youtube.com
  3. Restart the browser
  4. Ensure the extension still works as expected

The step (4) failed on versions prior to 1.63.94, i.e. extension didn't work without manual off/on on brave://extensions/.

stephendonner commented 10 months ago

Verified PASSED using

Brave | 1.63.102 Chromium: 120.0.6099.199 (Official Build) nightly (x86_64)
-- | --
Revision | e04c47f4648bb8a13cad74d386e61d33a80d70be
OS | macOS Version 14.3 (Build 23D5043d)

Steps:

  1. installed 1.63.102
  2. launched Brave
  3. installed https://chromewebstore.google.com/detail/clickbait-remover-for-you/omoinegiohhgbikclijaniebjpkeopip
  4. loaded youtube.com
  5. played a video
  6. restarted Brave
  7. played a different video
  8. opened brave://extensions

Confirmed I was able to use the provided extension both before and after restart, without additional tweaks

example example example example example example
Screenshot 2024-01-08 at 3 24 39 PM Screenshot 2024-01-08 at 3 24 42 PM Screenshot 2024-01-08 at 3 24 45 PM Screenshot 2024-01-08 at 3 25 10 PM Screenshot 2024-01-08 at 3 25 27 PM Screenshot 2024-01-08 at 3 25 41 PM
leteaaDEV commented 9 months ago

When is it expected to get released in latest builds?

bsclifton commented 9 months ago

Hi @leteaaDEV - this is merged already into both Nightly and Beta builds. 1.63 is scheduled to hit Release channel on February 20th

MadhaviSeelam commented 9 months ago

Verification PASSED using

Brave | 1.63.134 Chromium: 121.0.6167.85 (Official Build) beta (64-bit)
-- | --
Revision | cdcba6ef408b305ce19b1a9b3fabbb5e9e3b36bf
OS | Windows 11 Version 23H2 (Build 22631.3085)

Steps:

  1. installed 1.63.134
  2. launched Brave
  3. installed https://chromewebstore.google.com/detail/clickbait-remover-for-you/omoinegiohhgbikclijaniebjpkeopip
  4. loaded youtube.com videos
  5. played a video
  6. restarted Brave
  7. clicked extension and formatted the video titles to be lowercase and restarted browser

Confirmed extension worked as expected without manual toggle off/on

Confirmed when selected option of lowercase title shown correct case

example example example example example
image image image image image
ESUITDEV commented 9 months ago

This issue still exists in the latest version of Brave. Brave: v1.62.153 sys: MacOS v13.1 ext: https://chromewebstore.google.com/detail/esuit-ad-blocker-for-face/jkbklfkombochacjoeagggbiohipcbaj

This extension uses declarativeNetRequest to define rules that remove Facebook's CSP rules, but when I use cmd + q to exit Brave and then reopen the Brave browser to visit the FB page, declarativeNetRequest does not take any effect on FB. I have to manually disable this extension and then re-enable it in order for the declarativeNetRequest rules to be applied correctly.

I have now reported this issue to the users and have been working to get them back to Chrome as at least Chrome provides stable support.

ericplane commented 9 months ago

Hello @ESUITDEV the fix is currently only in nightly and beta builds 1.63 the devs said it will be in the release build which will drop around February 20th.

kjozwiak commented 9 months ago

Clearing QA-Pass labels as the above will need to be re-verified via 1.62.x. Used https://github.com/brave/brave-browser/issues/30854#issuecomment-1881983720 as the needed verification to uplift the above into 1.62.x.

The above requires 1.62.155 or higher for 1.62.x verification 👍

LaurenWags commented 9 months ago

Removed QA/Test-All-Platforms - per discussion with @goodov QA will check this on Windows and macOS.

cc @brave/qa-team

LaurenWags commented 9 months ago

Verified with

Brave | 1.62.155 Chromium: 121.0.6167.85 (Official Build) (x86_64)
-- | --
Revision | 91c989228daf153ef41bd965f268fabc7b9dbbf0
OS | macOS Version 13.6.4 (Build 22G513)

Reproduced the issue using 1.62.153 Chromium: 121.0.6167.85. Saw that the extension listed via https://github.com/brave/brave-browser/issues/30854#issuecomment-1880542650 didn't work on browser restart unless manually toggled off/back on.

1.62.153 before browser restart 1.62.153 after browser restart 1.62.153 after extension toggle off/on
1 2 3
Upgrade profile - PASSED 1. Reproduce the issue using `1.62.153` 2. Upgrade using `test` channel 3. Launch `1.62.155` 4. Navigate to youtube.com 5. Confirm extension works on youtube.com without visiting brave://extensions Screenshot 2024-01-30 at 8 43 35 AM
Clean Profile - PASSED 1. installed `1.62.155` 2. launched Brave, close and relaunch to pull griffin 3. installed `https://chromewebstore.google.com/detail/clickbait-remover-for-you/omoinegiohhgbikclijaniebjpkeopip` per https://github.com/brave/brave-browser/issues/30854#issuecomment-1880542650 4. loaded `youtube.com` 5. Confirmed clickbait tiles removed from YT videos (default setting for this extension) 6. played a video to confirm no issues 7. restarted Brave 8. Navigated to youtube.com again 9. Confirmed clickbait tiles still removed from YT videos 10. played a different video, confirmed no issues 11. Change extension to "lowercase" format video titles 12. Confirm change made on youtube (reload page if open) 13. Close browser 14. Relaunch 15. Visit youtube 16. Confirm change from step 11 is retained on browser relaunch ### Confirmed I was able to use the provided extension both before and after restart, without additional tweaks 3a | 3b | 5 | 9 | 11 | 12 | 16 ---------|----------|---------|----------|---------|---------|------- 3a | 3b | 5 | 9 | 11 | 12 | 16
MadhaviSeelam commented 9 months ago

Verification PASSED using

Brave | 1.62.155 Chromium: 121.0.6167.85 (Official Build) (64-bit)
-- | --
Revision | 91c989228daf153ef41bd965f268fabc7b9dbbf0
OS | Windows 11 Version 23H2 (Build 22631.3085)

Reproduced the issue from https://github.com/brave/brave-browser/issues/30854#issuecomment-1880542650

1.62.153 before browser restart 1.62.153 after browser restart 1.62.153 after extension toggle off/on
image image image

Clean profile:

  1. installed 1.62.153
  2. launched Brave
  3. installed https://chromewebstore.google.com/detail/clickbait-remover-for-you/omoinegiohhgbikclijaniebjpkeopip
  4. loaded youtube.com
  5. played a video
  6. restarted Brave

Confirmed extension worked as expected without manual toggle off/on

example example
image image

Upgrade:

  1. Installed 1.62.153
  2. launched Brave
  3. installed https://chromewebstore.google.com/detail/clickbait-remover-for-you/omoinegiohhgbikclijaniebjpkeopip
  4. loaded youtube.com videos
  5. restarted browser
  6. upgraded to 1.62.155

Confirmed extension worked as expected without manual toggle off/on

Confirmed when selected option of lowercase title shown correct case

before restarting browser restart browser After upgrade w/out extension toggle restart
image image image