sha*_*aka 9 javascript google-chrome-extension
从我的chrome扩展程序中,当用户从其他网站导航到Amazon.com但我遇到了一些问题时,我正试图获取引荐来源链接.
我正在使用 从chrome扩展名 html-page-from-chrome-extension 访问当前的html页面?noredirect = 1&lq = 1和 从"popup.html"访问当前选项卡DOM对象? from-popup-html但仍有问题.
我的js在confirmation.js:
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'loading') {
console.log(tab);
console.log(document);
//console.log(document.referrer);
}
});
Run Code Online (Sandbox Code Playgroud)
目前,当输出popup.html的DOM时; 不是用户所在选项卡的当前DOM.如何获取用户所在的当前选项卡的文档?
Console.log(tab)提供了用户所在的当前选项卡的信息,但我在此处看不到任何referrer属性.
关于如何解决这个问题的任何建议?
我的manifest.json:
"permissions": [
"activeTab",
"tabs",
"storage",
"notifications"
],
"content_scripts": [
{
"matches": ["https://www.amazon.com/*"],
"js": ["confirmation.js"]
}
]
Run Code Online (Sandbox Code Playgroud)
试试这个...
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if(changeInfo.state === 'complete'){
chrome.tabs.executeScript(tabId, {
code: "document.referrer;"
},
function(result) {
// Here, you you'll get the referrer
});
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
851 次 |
| 最近记录: |