[英]Is it possible to run javascript after a page has loaded using a omnibox extension?
I am trying to build an omnibox extension. 我正在尝试构建多功能框扩展程序。 Essentially I want this extension to pull up a url, then wait for that url to load, then execute some simple javascript.
本质上,我希望此扩展程序提取一个URL,然后等待该URL加载,然后执行一些简单的JavaScript。
Not sure if it's appreciated to put long blocks of code in questions, please feel free to yell at me if not. 不确定将较长的代码块放在问题中是否值得赞赏,如果没有,请随时对我大喊大叫。
manifest.json: manifest.json的:
{
"manifest_version": 2,
"name": "AutoATR",
"version": "0.1",
"omnibox": { "keyword" : "atr" },
"icons": {
"16": "package.png"
},
"background": {
"persistent": true,
"scripts": ["background.js"]
}
}
background.js: background.js:
function resetDefaultSuggestion() {
chrome.omnibox.setDefaultSuggestion({
description: 'atr: Placeholder: %s'
});
}
resetDefaultSuggestion();
function navigate(url) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs)
{
chrome.tabs.update(tabs[0].id, {url: url});
});
}
function finder(theID) {
document.getElementById('theElement').value=theID
document.getElementsByClassName('btn')[1].click()
}
chrome.omnibox.onInputEntered.addListener(function() {
// Navigate to URL
navigate("https://theURL.com");
});
// **** Would like to wait for just this tab to load.
// Then Execute finder(). ****
You can use manifest for your task: change location in background script location of tab to your pathURL and in manifest.json add next code : 您可以将清单用于您的任务:将tab的后台脚本位置中的位置更改为pathURL,并在manifest.json中添加下一个代码:
"content_scripts": [{
"matches": ["http://pathURL"],
"js": ["js/script.js"]
}]
js/script.js will be loaded after your browser tab path will match with " http://pathURL " pattern. 在您的浏览器选项卡路径与“ http:// pathURL ”模式匹配之后,将加载js / script.js。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.