javascript - How do i get referer from chrome extension webRequest api?
问题描述
I'm trying to get complete referer from chrome extension's webRequest api. This is how my function looks like. I need to find alternative to details.initiator
, as it's not enough precise.
//Listner to the onBeforeRequest event from webRequests api
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
//Checks if details url contains pixel.domain.com substring
if (details.url.toLowerCase().indexOf('pixel.domain.com') > 0) {
//Checks if map already contains array for this initiator
if (pixels.get(details.initiator)) {
var urls = pixels.get(details.initiator);
if (!urls.includes(details.url)) {
pixels.set(details.initiator, [...urls, details.url]);
}
} else {
//Else sets new (key, value)
pixels.set(details.initiator, [details.url]);
}
}
},
{ urls: ['<all_urls>'] }
);
Update: It can be also alternative to webRequest api, as i just need something, what tracks all requests made by the browser. Was considering also onRequest, but i'm not sure if it's not deprecated.
解决方案
I found a solution. Instead onBeforeRequest
, I use onBeforeSendHeaders
, where I have access to the request headers
推荐阅读
- c++ - 当我尝试从一个变量保存到另一个变量时写入访问冲突 C++
- kotlin-coroutines - 为什么 Kotlin 返回 Deferred<{Comparable & java.io.Serializable}> 而不是 Deferred
? - typeorm - 不要创建不存在的表
- java - 是否可以在启动图像点击时重定向到浏览器 URL?
- php - time() 会返回相同的输出吗?
- c++ - 我的公式有问题,我不知道是哪一个以及在哪里
- c++ - 为什么 C++ 中模板的大小是 1 字节?
- objective-c - NSSecureCoding 与核心数据中的符合元素数组
- flutter - Flutter,in_app_purchase:显示订阅到期日期或状态的方式
- php - 了解 PHP 中奇怪的引用/循环行为