declarativeNetRequest and update URL/HTTP parameters

111 views
Skip to first unread message

馮韋元Francois Devatine

unread,
Jan 29, 2019, 5:18:08 AM1/29/19
to Chromium Extensions
I'm looking at the doc for declarativeNetRequest and I can not find any info on how to dynamically update the URL parameters, or the HTTP request parameters of a request.
The use case of my extensions is the following:

- Let a website know that the user has an extension installed by adding an extra HTTP header x-extensions-installed in the request. WebRequest is able to catch the request, add the extra parameter and let it continue. Example: if we promote our extension on our website, we don't want to show the promotion to a user who already has the extension installed, so up to now we were using this method to do it.

- Dynamic Search engine parameters in manifest.json: unfortunately the search engine has no dynamic parameter approach. The search engine URL is hardcoded in the URL. Let's say that I want my extension to change the search engine and I need to differentiate 2 types of promotions. For example I would want one to be asearchengine.com?p={searchTerm}&origin=A and asearchengine.com?p={searchTerm}&origin=B to identify those 2 promotions.
1 way would be to create 2 extensions on the chrome store. Easy. But it doesn't scale up and gets messy if you may want 100+ extensions.
So WebRequest was able to catch the request on the fly and add the parameter &origin={origin}.
Can this be done with declarativeNetRequest?

Thanks,
Francois

Karan Bhatia

unread,
May 21, 2019, 4:36:44 PM5/21/19
to Chromium Extensions, fran...@gmail.com
- Dynamic Search engine parameters in manifest.json: unfortunately the search engine has no dynamic parameter approach. The search engine URL is hardcoded in the URL. Let's say that I want my extension to change the search engine and I need to differentiate 2 types of promotions. For example I would want one to be asearchengine.com?p={searchTerm}&origin=A and asearchengine.com?p={searchTerm}&origin=B to identify those 2 promotions.
1 way would be to create 2 extensions on the chrome store. Easy. But it doesn't scale up and gets messy if you may want 100+ extensions.
So WebRequest was able to catch the request on the fly and add the parameter &origin={origin}.
Can this be done with declarativeNetRequest?

Hey, can you elaborate on this further. The use case isn't that clear.

馮韋元Francois Devatine

unread,
May 21, 2019, 11:18:23 PM5/21/19
to Chromium Extensions, fran...@gmail.com
Hello Karan,

The manifest.json file can set a search engine, after installing the extension, the search engine will become the URL that is written in the manifest.json
The problem is that the parameters of that search engine URL in the manifest.json can only be hardcoded.
Problem is, our activity is to distribute extensions on behalf of multiple partners.
Say I want to distribute the extension to 3 partners. Each partner wants to be identified for each search made, obviously

Well, there is no way to do this in manifest.json.
Currently there are only 2 alternatives:
- Create 3 different extensions (this is very tricky when you have 100 partners instead of 3)
- Use WebRequest to dynamically update the parameter while having only 1 extension

So my original question was to find out wether or not declarativeNetRequest was able to do what WebRequest is able to do on this use case.

Thanks,
Francois
Reply all
Reply to author
Forward
0 new messages