简体   繁体   English

有没有办法在页面加载之后但在脚本执行之前运行内容脚本?

[英]Is there a way to run a content script after the page is loaded but before scripts are executed?

I'm writing a browser extension to intercept all the script tags on the page when it's loaded, but before they execute.我正在编写一个浏览器扩展来在页面加载时拦截页面上的所有脚本标签,但在它们执行之前。 To be clear, I'm not looking to block the scripts entirely;需要明确的是,我并不想完全阻止脚本。 I just want to intercept and analyze/modify them before they're run.我只想在它们运行之前拦截和分析/修改它们。

Is there a way to do this?有没有办法做到这一点?

I'm aware of onbeforescriptexecute for Firefox and its polyfill for Chrome, but I'm hoping for something more "official" and cross-browser...我知道 Firefox 的onbeforescriptexecute及其适用于 Chrome 的 polyfill,但我希望有更多“官方”和跨浏览器的东西......

As answered by CertainPerformance in the comments, you can use a MutationObserver to observe changes to the DOM as shown here: https://stackoverflow.com/a/59518023正如CertainPerformance在评论中回答的那样,您可以使用 MutationObserver 来观察 DOM 的变化,如下所示: https://stackoverflow.com/a/59518023

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在加载DOM之后但在执行任何页面脚本之前运行Google Chrome内容脚本? - Is there a way to run a Google Chrome content script after the DOM is loaded but before any page scripts are executed? 通过Ajax加载其他页面内容后运行脚本 - Run script after additional page content is loaded via Ajax Chrome 扩展:在页面上运行任何嵌入式脚本之前运行内容脚本 - Chrome Extension: Run Content Script before any Embedded Scripts run on Page 如何在为 Google Chrome 扩展程序完全加载页面之前运行内容脚本 - How to make a content script run before a page is fully loaded for Google Chrome Extensions 内部脚本完全加载后如何运行脚本? - How do I run a script after internal scripts are fully loaded? jQuery-在所有页面加载后执行附加脚本 - jQuery - appended script executed after all page loaded javascript在页面加载后作为最后一个脚本运行 - javascript run as last script after page loaded 在页面上的所有脚本完全加载后运行 js 函数 - run js function after all scripts on page are fully loaded 在加载的脚本中,在.ready回调之前调用JQuery .load回调,初始化加载的脚本的正确方法是什么? - JQuery .load callback is called before .ready callback in loaded script, what is proper way of initialization loaded scripts? 页面完全加载后如何执行内容脚本 - How to execute content script after the page is loaded completely
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM