我正在开发一个扩展程序,它将在所有 Google 搜索 URL 上执行特定操作 - 但不会在其他网站或 Google 页面上执行。在自然语言中,匹配模式是:
'*://')'www'或'')'google''.com')和多部分国家/地区 TLD(例如'.co.uk')'/search?'许多人说“匹配所有谷歌搜索页面使用的内容,"*://*.google.com/search?*"但这显然是不正确的,因为它不会匹配 google.co.uk 等国家顶级域名 (TLD)”。
因此下面的代码根本不起作用:
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
alert('This never happens');
}, {
urls: [
"*://*.google.*/search?*",
"*://google.*/search?*",
],
types: ["main_frame"]
},
["blocking"]
);
Run Code Online (Sandbox Code Playgroud)
使用"*://*.google.com/search?*"as 匹配模式确实有效,但我担心我需要每个 Google 本地化的列表才能成为有效的策略。