Tamar Y
unread,Nov 1, 2023, 5:53:38 AM11/1/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium Extensions
Hello Chrome Developers,
I am attempting to set the Referer header to a specific value using the chrome.declarativeNetRequest API. Here is the code snippet I've used:
chrome.runtime.onInstalled.addListener(async () => {
await chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [1],
addRules: [{
id: 1,
priority: 1,
action: {
type: chrome.declarativeNetRequest.RuleActionType.MODIFY_HEADERS,
requestHeaders: [
{
header: 'Referer',
operation: chrome.declarativeNetRequest.HeaderOperation.SET,
value: 'test'
},
{
header: 'Sec-Fetch-Site',
operation: chrome.declarativeNetRequest.HeaderOperation.SET,
value: 'same-origin'
}
]
},
condition: {
urlFilter: '"|https*"',
resourceTypes: [
chrome.declarativeNetRequest.ResourceType.MAIN_FRAME,
chrome.declarativeNetRequest.ResourceType.SUB_FRAME,
chrome.declarativeNetRequest.ResourceType.STYLESHEET,
chrome.declarativeNetRequest.ResourceType.SCRIPT,
chrome.declarativeNetRequest.ResourceType.IMAGE,
chrome.declarativeNetRequest.ResourceType.OBJECT,
chrome.declarativeNetRequest.ResourceType.XML_HTTP_REQUEST,
chrome.declarativeNetRequest.ResourceType.OTHER
]
}
}]
});
});
However, I'm encountering the following error:
TypeError: Error in invocation of declarativeNetRequest.updateDynamicRules(declarativeNetRequest.UpdateRuleOptions options, optional function callback): Error at parameter 'options': Error at property 'addRules': Error at index 6: Error at property 'condition': Error at property 'resourceTypes': Error at index 6: Invalid type: expected declarativeNetRequest.ResourceType, found undefined.
It seems like there's an issue with the chrome.declarativeNetRequest.ResourceType.XML_HTTP_REQUEST, even though I've taken its value from the enum list.
But the more problematic issue is the point that I've noticed that this code is working as expected when running the extension in a browser with web security disabled using the flags --disable-web-security --disable-gpu. However, it does not work in regular browsers. Here is a snippet of my permissions from the manifest:
"permissions": [
"activeTab",
"storage",
"tabs",
"webNavigation",
"alarms",
"notifications",
"nativeMessaging",
"downloads",
"unlimitedStorage",
"cookies",
"gcm",
"webRequest",
"sidePanel",
"declarativeNetRequest",
"declarativeNetRequestWithHostAccess",
"declarativeNetRequestFeedback"
],
"host_permissions": [
"<all_urls>",
"http://*/",
"https://*/"
]
Did I miss something?
Thank you for your assistance!