Google chrome.history.deleteUrl 或 chrome.browsingData.remove 的扩展 HostEquals
Google Extension HostEquals for chrome.history.deleteUrl or chrome.browsingData.remove
我正在做一个 chrome 扩展项目,但无法让 host equals 工作,所以它涵盖了用户经过该域的所有地方。例如,如果用户转到 https://www.google.com/imghp?hl=en 让代码在那里再次执行。这可以在 background.js 文件中完成吗?我认为匹配模式在这里不起作用。如果设置为确切的 url chrome.history.deleteUrl({ url: 'www.google.com'} 下面的代码会正确执行,但如果我尝试将其设置为 hostEquals 则不会。我不认为这个函数允许 hostEquals。感谢您的帮助。
background.js 文件-
'use strict';
chrome.webNavigation.onCompleted.addListener(function() {
}, {url: [{urlMatches : 'www.google.com'}]});
var callback = function () {
alert("History is clearing");
};
chrome.history.deleteUrl(
{ url: [{hostEquals: 'www.google.com'}]}
, callback);
有没有办法可以将 hostEquals 作为变量输入? HostEquals 也不适用于 chrome.browsingData.remove()
请不要发明不存在的属性:如 documentation says deleteUrl
has only url
property, which is "The URL to remove", not a pattern. If you want to remove all URLs from a domain then first find them using chrome.history.search. See also demo extensions.
更好的解决方案可能是使用 details.url
提供给 onCompleted 回调,如您在 documentation. See also the demo extensions 中所见,并自行查找更多示例。
chrome.webNavigation.onCompleted.addListener(details => {
chrome.history.deleteUrl({url: details.url});
}, {url: [{hostEquals: 'www.google.com'}]});
代码中的另一个问题是 urlMatches
是错误的工具,因为它是一个正则表达式,可以匹配不相关 URL 中的 https://foo/bar/www1google2com。
P.S。考虑使用 onCommitted 而不是 onCompleted 来更早地执行检查。
我正在做一个 chrome 扩展项目,但无法让 host equals 工作,所以它涵盖了用户经过该域的所有地方。例如,如果用户转到 https://www.google.com/imghp?hl=en 让代码在那里再次执行。这可以在 background.js 文件中完成吗?我认为匹配模式在这里不起作用。如果设置为确切的 url chrome.history.deleteUrl({ url: 'www.google.com'} 下面的代码会正确执行,但如果我尝试将其设置为 hostEquals 则不会。我不认为这个函数允许 hostEquals。感谢您的帮助。
background.js 文件-
'use strict';
chrome.webNavigation.onCompleted.addListener(function() {
}, {url: [{urlMatches : 'www.google.com'}]});
var callback = function () {
alert("History is clearing");
};
chrome.history.deleteUrl(
{ url: [{hostEquals: 'www.google.com'}]}
, callback);
有没有办法可以将 hostEquals 作为变量输入? HostEquals 也不适用于 chrome.browsingData.remove()
请不要发明不存在的属性:如 documentation says deleteUrl
has only url
property, which is "The URL to remove", not a pattern. If you want to remove all URLs from a domain then first find them using chrome.history.search. See also demo extensions.
更好的解决方案可能是使用 details.url
提供给 onCompleted 回调,如您在 documentation. See also the demo extensions 中所见,并自行查找更多示例。
chrome.webNavigation.onCompleted.addListener(details => {
chrome.history.deleteUrl({url: details.url});
}, {url: [{hostEquals: 'www.google.com'}]});
代码中的另一个问题是 urlMatches
是错误的工具,因为它是一个正则表达式,可以匹配不相关 URL 中的 https://foo/bar/www1google2com。
P.S。考虑使用 onCommitted 而不是 onCompleted 来更早地执行检查。