提取快速关闭选项卡的浏览器访问的链接
win11下,微信文件传输助手在chrome下 版本 141.0.7390.123(正式版本) (64 位)点击发送来的文件,新选项卡打开后,快速关闭,导致无法下载文件。
可以在终端使用如下获得网址链接
(function() {
const originalOpen = window.open;
window.open = function(url, name, features) {
console.log('即将打开的新标签页URL:', url);
// 复制到剪贴板
navigator.clipboard.writeText(url).then(() => {
console.log('URL已复制到剪贴板');
});
return originalOpen.call(this, url, name, features);
};
})();
或者
(function() {
// 覆盖window.open方法
const originalOpen = window.open;
window.open = function(...args) {
console.log('新标签页URL:', args[0]);
// 立即复制到剪贴板
navigator.clipboard.writeText(args[0]).then(() => {
alert('URL已复制: ' + args[0]);
});
return originalOpen.apply(this, args);
};
// 也监控location.href的变化
let oldHref = document.location.href;
const observer = new MutationObserver(() => {
if (oldHref !== document.location.href) {
console.log('页面跳转到:', document.location.href);
navigator.clipboard.writeText(document.location.href);
oldHref = document.location.href;
}
});
observer.observe(document, { childList: true, subtree: true });
})();
移除
// 获取原始的 window.open(通过 iframe)
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
const originalOpen = iframe.contentWindow.open;
document.body.removeChild(iframe);
// 恢复原始的 window.open
window.open = originalOpen;
console.log('已恢复原始的 window.open 函数');
浙公网安备 33010602011771号