I am building a Chrome extension, and one of the behaviors is to spawn a popup window with a specified size and location:(我正在构建一个Chrome扩展程序,其行为之一是生成具有指定大小和位置的弹出窗口:)
url = "https://google.com"
chrome.windows.create(
{
'url': url,
'type': 'popup',
'width': Math.floor(screen.availWidth / 2),
'height': Math.floor(screen.availHeight / 2),
'left': Math.floor(screen.availWidth / 2),
'top': 0
},
function(window) {}
);
At this point I need to run some Javascript on the spawned page.(此时,我需要在生成的页面上运行一些Javascript。) I understand that I can declare a content script in my manifest that matches url
, however the url is actually dynamic, and can be pretty much anything.(我知道我可以在清单中声明与url
匹配的内容脚本,但是url实际上是动态的,几乎可以是任何东西。)
So, my best guess right now would be to add a content script with matcher https://*/*
, and through some other means determine that this is the page which was spawned by the extension - either through adding some query param, or through the extension messaging system.(因此,我现在最好的猜测是添加一个带有匹配器https://*/*
的内容脚本,并通过其他方式确定这是扩展程序生成的页面-通过添加一些查询参数,或者通过扩展消息系统。)
This approach seems kind of hacky, though.(但是,这种方法似乎有点怪异。) Does anyone know of a more 'proper' way to do this?(有谁知道一种更“合适”的方式来做到这一点?)
ask by max pleaner translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…