Question about the race condition of DNR dynamic rules and page loading

66 views
Skip to first unread message

Lu Xu

unread,
Jun 24, 2024, 9:49:21 PM (4 days ago) Jun 24
to Chromium Extensions
Hi everyone,
I have a question about declarativeNetRequest dynamic rules, according to the doc, the dynamic rules should be persistent, my understanding is if user restart Chrome, the dynamic rules still persist.

I have a very simple dynamic rule to add a custom header to a specific url, like

chrome.declarativeNetRequest.updateDynamicRules({
  addRules: [
    {
      id: 999,
      priority: 1,
      condition: {
        urlFilter: "https://test.mydomain.com/home/*",
        resourceTypes: ["main_frame"],
      },
      action: {
        type: "modifyHeaders",
        requestHeaders: [
          {
            header: "X-EXT-VER",
            operation: "set",
            value: "6.30.0",
          },
        ],
      },
    },
  ],
});

this works when I open Chrome, open a new tab and visit "https://test.mydomain.com/home/", however, some of my users(windows user) reported that they create a shortcut of the url (like dragging the url directly to desktop), then they can open that url directly when Chrome is closed. In this case, the custom header is not set, after they refresh the page, the header is set correctly.

I suppose this might be a racing condition, is it possible that the moment that Chrome starts and load the page, the extension rules are still not applied?
If this is the case, any ideas how to fix it?

Thank you very much

woxxom

unread,
Jun 25, 2024, 2:59:04 AM (4 days ago) Jun 25
to Chromium Extensions, Lu Xu
Sounds like a bug in Chrome. You can report it in https://crbug.com.

The workaround may be to use "redirect" rule to an extension page for this URL (example) and in chrome.runtime.onStartup you will add your original rule with `priority:2` using updateSessionRules, then you'll redirect all those redirected tabs to their original urls.

Kabir Singh

unread,
Jun 25, 2024, 5:17:56 AM (4 days ago) Jun 25
to Chromium Extensions, woxxom, Lu Xu
Hey anyone mind taking a look at my issue ? Google groups conversation

Lu Xu

unread,
Jun 25, 2024, 8:54:30 PM (3 days ago) Jun 25
to woxxom, Chromium Extensions
Thanks a lot woxxom, I will try to reproduce it first, then report it.
As for the workaround of the "redirect" rule, if the root cause is indeed page loading is faster than the rules are applied, it will not work either right? But it is good to know the "chrome.runtime.onStartup" API, maybe I can check if the rules exist and refresh the tab.

woxxom

unread,
Jun 26, 2024, 12:52:19 AM (3 days ago) Jun 26
to Chromium Extensions, Lu Xu, Chromium Extensions, woxxom
>  it will not work either right? 

We don't know what exactly is causing the bug. It may be limited to headers.

Lu Xu

unread,
Jun 26, 2024, 9:57:27 PM (2 days ago) Jun 26
to woxxom, Chromium Extensions
I can reproduce it
Reply all
Reply to author
Forward
0 new messages