Question about Manifest V3

858 views
Skip to first unread message

kinoko koutya

unread,
May 30, 2023, 8:16:31 AM5/30/23
to Chromium Extensions
I want to create a Chrome Extension using JavaScript as follows:
Manifest version: 3.

1. Utilize chrome.webRequest.onBeforeRequest.addListener to retrieve request information from the browser.

2. Send a request to a separate server using the fetch function and receive the response.

3. After receiving the response from the separate server, control the request from the browser (allow or block).

I want to execute the above process, but before receiving the response from the separate server in step 2, the request from the browser is sent.
In Manifest V2, this could be handled by using webRequestBlocking, but it does not work in V3 since webRequestBlocking is not available.

Is there a workaround for this issue?

Oliver Dunk

unread,
May 30, 2023, 8:23:18 AM5/30/23
to kinoko koutya, Chromium Extensions
Hi Kinoko,

In general this sort of thing isn't supported in Manifest V3. There are two big limitations with that approach:
  • The fetch request can take an arbitrary amount of time, and that delays requests.
  • This involves the extension having access to all of the request's data, which is good to avoid if possible. That remains possible in MV3 with the webRequest API but we're trying to reduce the number of cases where it's necessary.
Could you share a bit more about your use case? That would help point towards the best solution.

One of the things I often recommend here is using an HTTP proxy instead of an extension. Or, if your extension is installed by policy, we do still support blocking webRequest in those cases (though notably even in MV2 adding a fetch to the chain wasn't explicitly supported, and required using XMLHTTPRequest which was sort of an unintended feature - the blocking nature of that API is one of the reasons fetch was introduced).
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/f1473ddf-016a-4b7e-88c6-e3dde91bbf2an%40chromium.org.

kinoko koutya

unread,
May 31, 2023, 2:57:49 AM5/31/23
to Chromium Extensions, Oliver Dunk, Chromium Extensions, kinoko koutya
thanks for the reply.


>Could you share a bit more about your use case? That would help point towards the best solution.
I am planning to create a browser extension that blocks requests to dangerous websites when a request occurs.
When I use the fetch function to send a request to a different server, I intend to wait using the "await" function until I receive the response.
In Manifest V3, is it true that requests from the browser are sent to the website before the processing inside the onBeforeRequest function is completed?
If there are any websites or documentation that describe this specification, could you please let me know?


>One of the things I often recommend here is using an HTTP proxy instead of an extension.
I have also considered using a proxy, but currently, it is challenging to implement.
Therefore, I prefer to use a browser extension for this purpose.


>Or, if your extension is installed by policy, we do still support blocking webRequest in those cases
If you distribute an extension using the "Force install apps and extensions" procedure at the URL below, my understanding is that you can use "blocking webRequest".
Is my understanding correct?
Also, in that case, do you need to use Manifest V2 for the extension version instead of Manifest V3?
https://support.google.com/chrome/a/answer/6306504?hl=en&sjid=5599670035449560702-AP

2023年5月30日火曜日 21:23:18 UTC+9 Oliver Dunk:

Carrie leann Luke

unread,
May 31, 2023, 3:05:30 AM5/31/23
to kinoko koutya, Chromium Extensions, Oliver Dunk

Oliver Dunk

unread,
May 31, 2023, 5:08:45 AM5/31/23
to kinoko koutya, Chromium Extensions
thanks for the reply.
 
No problem! Always enjoy talking through different use cases.

In Manifest V3, is it true that requests from the browser are sent to the website before the processing inside the onBeforeRequest function is completed?
If there are any websites or documentation that describe this specification, could you please let me know?

There aren't any specific implementation changes as far as I'm aware, but `blocking` is no longer allowed in the array passed as a final parameter to the API.


If the optional opt_extraInfoSpec array contains the string 'blocking' (only allowed for specific events), the callback function is handled synchronously. That means that the request is blocked until the callback function returns.
 
Which also implies the opposite, that this isn't synchronous by default.

I have also considered using a proxy, but currently, it is challenging to implement.

At the moment, a proxy is the only option that can give you the control you want. If you have any specific limitations with that approach, though, I'd be curious to know, since we are always interested to hear about gaps in the platform. But I don't expect anything to change here in the short term.

If you distribute an extension using the "Force install apps and extensions" procedure at the URL below, my understanding is that you can use "blocking webRequest". Is my understanding correct?

That's right. That said, you still have to respond synchronously, so you cannot meaningfully use the fetch API.

Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB

kinoko koutya

unread,
Jun 3, 2023, 9:31:57 PM6/3/23
to Chromium Extensions, Oliver Dunk, Chromium Extensions, kinoko koutya

Thank you for your response.
I understand that with Manifest V3, the blocking mode in onBeforeRequest will no longer be available, making it difficult to delay requests.

I will reconsider using a proxy for control.
I will also explore the possibility of installing the extension through Google Admin and using the "blocking webRequest" method.
Thank you for answering my question.
2023年5月31日水曜日 18:08:45 UTC+9 Oliver Dunk:
Reply all
Reply to author
Forward
0 new messages