簡體   English   中英

chrome.history.deleteUrl 或 chrome.browsingData.remove 的 Google 擴展 HostEquals

[英]Google Extension HostEquals for chrome.history.deleteUrl or chrome.browsingData.remove

我正在開發一個 chrome 擴展項目,但無法讓 host equals 工作,因此它涵蓋了用戶經過域的所有地方。 例如,如果用戶轉到https://www.google.com/imghp?hl=en讓代碼在那里再次執行。 這可以在 background.js 文件中執行嗎? 我認為匹配模式在這里不起作用。 The below code executes properly if set to an exact url chrome.history.deleteUrl({ url: 'www.google.com'} but not if I try to set it to hostEquals. I dont think this function allows hostEquals. Thank you for任何幫助。

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()

請不要發明不存在的屬性:正如文檔所述, deleteUrl只有url屬性,即“要刪除的 URL”,而不是模式。 如果要從域中刪除所有 URL,請首先使用chrome.history.search找到它們。 另請參閱 演示擴展

更好的解決方案可能是使用details.url提供給 onCompleted 回調,您可以在文檔中看到。 另請參閱演示擴展並自行查找更多示例。

chrome.webNavigation.onCompleted.addListener(details => {
  chrome.history.deleteUrl({url: details.url});
}, {url: [{hostEquals: 'www.google.com'}]});

您的代碼中的另一個問題是urlMatches是錯誤的工具,因為它是一個正則表達式,可以在不相關的 URL 中匹配https://foo/bar/www1google2com

PS 考慮使用 onCommitted 而不是 onCompleted 更早地執行檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM