![](/img/trans.png)
[英]Chrome extension's content script not getting injected on specific websites
[英]Getting chrome extension id programatically in injected script
在我的內容腳本中,我正在使用這種方法來訪問網頁的變量:
function exec(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = '(' + fn + ')();';
document.body.appendChild(script); //run the script
document.body.removeChild(script); //clean up
}
exec( function(){
var test = websiteVar
chrome.runtime.sendMessage("extensionID", {test: test}, function(response) {
});
});
上面寫着extensionID的地方,如果我對其進行硬編碼,它將起作用。 但是,我無法使用chrome.runtime.id
因為它已注入頁面中。 我想我讀到它們在相同的上下文中不起作用。
有沒有辦法以編程方式獲取擴展名?
上述wOxxOm的示例:
function exec(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = '(' + fn + ')("' + chrome.runtime.id +'")';
document.body.appendChild(script); //run the script
document.body.removeChild(script); //clean up
}
exec( function(extensionID){
var test = websiteVar;
chrome.runtime.sendMessage(extensionID, {test: test}, function(response) {
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.