我正在开发一个带扩展iframe元素的在线网页的选项选项卡的Chrome扩展。只要用户点击iframe中的某个链接,浏览器就会创建一个新的历史记录,并且浏览器的后退/前进按钮被激活。如何清除标签页上的历史记录关闭?
我想清除用户关闭标签后创建的所有历史记录,并且如果可能的话,停止浏览器将标签添加到“历史 - >最近关闭”菜单。
我尝试用浏览器控制台内不同的API,并且没有以下的似乎是工作的打算:
window.onunload = function() {
// Using the `chrome.history` API
chrome.history.deleteUrl({url: 'https://example.tld/'}, console.log);
// Using the `chrome.browsingData` API
chrome.browsingData.removeHistory({
"since": (new Date()).getTime() - 1000000
}, console.log);
};
虽然这种成功没有任何错误的执行,我仍然可以恢复选项卡通过“历史 - >最近关闭”,并使用后退/前进按钮导航回iframe元素中加载的URL(即“https://example.tld/”)。我怎样才能阻止这种行为?
注意:“history”和“browsingData”权限都是通过“manifest.json”文件获取的。
'onunload'用于快速同步清理,因此它不适用于具有异步回调的chrome API。另外,内容脚本无法访问chrome.browsingData。您需要[chrome.tabs API](https://developer.chrome.com/extensions/tabs)中的背景页面(或事件页面)和特殊事件,另请参阅[体系结构概述](https:// developer .chrome.com /扩展/概述#拱)。 – wOxxOm
Ref https://superuser.com/q/359879/78897 – Pacerier