I'm developing an extension which will perform a certain action on all Google search URLs - but not on other websites or Google pages. In natural language the match pattern is:
- Any protocol (
'*://'
)
- Any subdomain or none (
'www'
or ''
)
- The domain string must equal
'google'
- Any TLD including three-letter TLDs (e.g.
'.com'
) and multi-part country TLDs (e.g. '.co.uk'
)
- The first 8 letters of the path must equal
'/search?'
Many people say 'to match all google search pages use "*://*.google.com/search?*"
but this is patently untrue as it will not match national TLDs like google.co.uk.
Thus the following code does not work at all:
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
alert('This never happens');
}, {
urls: [
"*://*.google.*/search?*",
"*://google.*/search?*",
],
types: ["main_frame"]
},
["blocking"]
);
Using "*://*.google.com/search?*"
as the match pattern does work, but I fear I would need a list of every single Google localisation for that to be an effective strategy.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…