pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  1. <tfoot id='84j6Y'></tfoot>

    <small id='84j6Y'></small><noframes id='84j6Y'>

      <bdo id='84j6Y'></bdo><ul id='84j6Y'></ul>
  2. <i id='84j6Y'><tr id='84j6Y'><dt id='84j6Y'><q id='84j6Y'><span id='84j6Y'><b id='84j6Y'><form id='84j6Y'><ins id='84j6Y'></ins><ul id='84j6Y'></ul><sub id='84j6Y'></sub></form><legend id='84j6Y'></legend><bdo id='84j6Y'><pre id='84j6Y'><center id='84j6Y'></center></pre></bdo></b><th id='84j6Y'></th></span></q></dt></tr></i><div class="x7zvpz7" id='84j6Y'><tfoot id='84j6Y'></tfoot><dl id='84j6Y'><fieldset id='84j6Y'></fieldset></dl></div>
    <legend id='84j6Y'><style id='84j6Y'><dir id='84j6Y'><q id='84j6Y'></q></dir></style></legend>

      為什么這段代碼不起作用?我正在創建一個 Firef

      Why is this code not working? I am creating a Firefox extension but the code is not running. But if I paste the code into the console it works(為什么這段代碼不起作用?我正在創建一個 Firefox 擴展,但代碼沒有運行.但是

        <tbody id='ZLA0S'></tbody>
    1. <small id='ZLA0S'></small><noframes id='ZLA0S'>

        • <tfoot id='ZLA0S'></tfoot>

          1. <legend id='ZLA0S'><style id='ZLA0S'><dir id='ZLA0S'><q id='ZLA0S'></q></dir></style></legend>
            <i id='ZLA0S'><tr id='ZLA0S'><dt id='ZLA0S'><q id='ZLA0S'><span id='ZLA0S'><b id='ZLA0S'><form id='ZLA0S'><ins id='ZLA0S'></ins><ul id='ZLA0S'></ul><sub id='ZLA0S'></sub></form><legend id='ZLA0S'></legend><bdo id='ZLA0S'><pre id='ZLA0S'><center id='ZLA0S'></center></pre></bdo></b><th id='ZLA0S'></th></span></q></dt></tr></i><div class="jjtrlzt" id='ZLA0S'><tfoot id='ZLA0S'></tfoot><dl id='ZLA0S'><fieldset id='ZLA0S'></fieldset></dl></div>
              <bdo id='ZLA0S'></bdo><ul id='ZLA0S'></ul>

                本文介紹了為什么這段代碼不起作用?我正在創建一個 Firefox 擴展,但代碼沒有運行.但是,如果我將代碼粘貼到控制臺中,它就可以工作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我做了一個 Firefox 擴展來獲取所有請求的 url 并顯示它們.但代碼只有在我將其粘貼到控制臺時才有效.

                I make a firefox extension that get all the request url's and displays them. But the code only works if I paste it in the console.

                當擴展程序加載時它沒有顯示任何錯誤,它似乎只是不會運行

                when the extension loads it doesn't show any error, it seems like it just won't run

                這是完整的代碼

                xhrScript.js

                (function(){
                
                    const proxiedOpen = XMLHttpRequest.prototype.open;
                    window.XMLHttpRequest.prototype.open = function ( _, url) {
                        this.__URL = url;
                        return proxiedOpen.apply(this, arguments);
                    };
                
                    const proxiedSend = window.XMLHttpRequest.prototype.send;
                    window.XMLHttpRequest.prototype.send = function () {
                        const { protocol, host } = window.location;
                        // showing only when it paste in console
                        console.log("full request url ", `${protocol}//${host}${this.__URL}`);
                        return proxiedSend.apply(this, [].slice.call(arguments));
                    };
                
                })();
                
                // this works all times
                document.body.style.border = "7px solid blue";
                

                ma??nifest.json

                {
                    "manifest_version": 2,
                    "name": "XHR request urls",
                    "version": "1.0",
                    "description": "get all the request url's",
                
                    "content_scripts": [
                      {
                        "matches": ["*://*/*"],
                        "js": ["xhrScript.js"]
                      }
                    ]  
                }
                

                如您所見,最后一行是 document.body.style.border = "7px solid blue";,每次都可以正常工作.但是 XMLHttpRequest opensend 方法不起作用.僅當我將代碼粘貼到控制臺時才有效.

                As you can see, in the last line is document.body.style.border = "7px solid blue";, this works fine every time. But the XMLHttpRequest open and send methods don't work. only works if I paste the code in the console.

                如果您想查看示例,可以嘗試將 xhrScript.js 代碼復制并粘貼到 https://reactjs.org(這是一個 SPA,所以很容易檢查我想要什么)在 devTools 控制臺中,并查看所有請求.

                if you want see an example, you can try copy and paste the xhrScript.js code in https://reactjs.org (it's a SPA, so it's easy to check what I want) in the devTools console, and see all the request.

                我不知道為什么這段代碼只有在控制臺粘貼時才會運行

                I don't know why this code only runs when it is pasted in console

                推薦答案

                內容腳本在隔離的 JavaScript 環境中運行,這意味著 window 及其內容與頁面隔離,因此當您修改它時,您只修改內容腳本的版本.

                Content scripts run in an isolated JavaScript environment meaning that window and its contents are isolated from the page so when you modify it, you only modify the content script's version.

                有兩種解決方案:

                1. Firefox 專用.

                1. Firefox-specific.

                使用 wrappedJSObjectexportFunction 訪問頁面上下文(更多信息):

                Use wrappedJSObject and exportFunction to access the page context (more info):

                const urls = new WeakMap();
                const origXhr = hookPagePrototype('XMLHttpRequest', {
                  open(method, url) {
                    urls.set(this, url);
                    return origXhr.open.apply(this, arguments);
                  },
                  send() {
                    console.log('Sending', new URL(urls.get(this), location).href);
                    return origXhr.send.apply(this, arguments);
                  },
                });
                
                function hookPagePrototype(protoName, funcs) {
                  const proto = wrappedJSObject[protoName].prototype;
                  const oldFuncs = {};
                  for (const [name, fn] of Object.entries(funcs)) {
                    oldFuncs[name] = exportFunction(proto[name], wrappedJSObject);
                    proto[name] = exportFunction(fn, wrappedJSObject);
                  }
                  return oldFuncs;
                }
                

              • Chrome 兼容.

              • Chrome-compatible.

                使用 DOM 腳本在頁面上下文中運行代碼:說明.

                它不適用于受嚴格的 Content-Security-Policy (CSP) 保護的頁面,該 CSP 會阻止腳本執行,因此在為 Firefox 編寫擴展時,我們應該改用 wrappedJSObject 方法.

                It won't work on pages protected by a strict Content-Security-Policy (CSP) that prevents script execution so when writing an extension for Firefox we should use wrappedJSObject method instead.

                這篇關于為什么這段代碼不起作用?我正在創建一個 Firefox 擴展,但代碼沒有運行.但是,如果我將代碼粘貼到控制臺中,它就可以工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
              • 相關文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)

                  <tbody id='5Q7Wz'></tbody>
                  <bdo id='5Q7Wz'></bdo><ul id='5Q7Wz'></ul>
                • <i id='5Q7Wz'><tr id='5Q7Wz'><dt id='5Q7Wz'><q id='5Q7Wz'><span id='5Q7Wz'><b id='5Q7Wz'><form id='5Q7Wz'><ins id='5Q7Wz'></ins><ul id='5Q7Wz'></ul><sub id='5Q7Wz'></sub></form><legend id='5Q7Wz'></legend><bdo id='5Q7Wz'><pre id='5Q7Wz'><center id='5Q7Wz'></center></pre></bdo></b><th id='5Q7Wz'></th></span></q></dt></tr></i><div class="5d77vbd" id='5Q7Wz'><tfoot id='5Q7Wz'></tfoot><dl id='5Q7Wz'><fieldset id='5Q7Wz'></fieldset></dl></div>
                • <tfoot id='5Q7Wz'></tfoot>

                    <legend id='5Q7Wz'><style id='5Q7Wz'><dir id='5Q7Wz'><q id='5Q7Wz'></q></dir></style></legend>

                    <small id='5Q7Wz'></small><noframes id='5Q7Wz'>

                          主站蜘蛛池模板: 液压油缸-液压缸厂家价格,液压站系统-山东国立液压制造有限公司 液压油缸生产厂家-山东液压站-济南捷兴液压机电设备有限公司 | 连栋温室大棚建造厂家-智能玻璃温室-薄膜温室_青州市亿诚农业科技 | 智能气瓶柜(大型气瓶储存柜)百科 | 智能家居全屋智能系统多少钱一套-小米全套价格、装修方案 | 哲力实业_专注汽车涂料汽车漆研发生产_汽车漆|修补油漆品牌厂家 长沙一级消防工程公司_智能化弱电_机电安装_亮化工程专业施工承包_湖南公共安全工程有限公司 | 上海单片机培训|重庆曙海培训分支机构—CortexM3+uC/OS培训班,北京linux培训,Windows驱动开发培训|上海IC版图设计,西安linux培训,北京汽车电子EMC培训,ARM培训,MTK培训,Android培训 | arch电源_SINPRO_开关电源_模块电源_医疗电源-东佑源 | 苏州西装定制-西服定制厂家-职业装定制厂家-尺品服饰西装定做公司 | 北京康百特科技有限公司-分子蒸馏-短程分子蒸馏设备-实验室分子蒸馏设备 | 智慧养老_居家养老_社区养老_杰佳通| 高压无油空压机_无油水润滑空压机_水润滑无油螺杆空压机_无油空压机厂家-科普柯超滤(广东)节能科技有限公司 | 南汇8424西瓜_南汇玉菇甜瓜-南汇水蜜桃价格 | 过跨车_过跨电瓶车_过跨转运车_横移电动平车_厂区转运车_无轨转运车 | 手术室净化厂家_成都实验室装修公司_无尘车间施工单位_洁净室工程建设团队-四川华锐16年行业经验 | 细胞染色-流式双标-试剂盒免费代做-上海研谨生物科技有限公司 | 合肥宠物店装修_合肥宠物美容院装修_合肥宠物医院设计装修公司-安徽盛世和居装饰 | 铣刨料沥青破碎机-沥青再生料设备-RAP热再生混合料破碎筛分设备 -江苏锡宝重工 | 风淋室生产厂家报价_传递窗|送风口|臭氧机|FFU-山东盛之源净化设备 | 成都装修公司-成都装修设计公司推荐-成都朗煜装饰公司 | 彼得逊采泥器-定深式采泥器-电动土壤采样器-土壤样品风干机-常州索奥仪器制造有限公司 | 昆明挖掘机修理厂_挖掘机翻新再制造-昆明聚力工程机械维修有限公司 | 净化车间装修_合肥厂房无尘室设计_合肥工厂洁净工程装修公司-安徽盛世和居装饰 | 上海公众号开发-公众号代运营公司-做公众号的公司企业服务商-咏熠软件 | 耐破强度测试仪-纸箱破裂强度试验机-济南三泉中石单品站 | 飞象网 - 通信人每天必上的网站| 隧道风机_DWEX边墙风机_SDS射流风机-绍兴市上虞科瑞风机有限公司 | 工业用品一站式采购平台|南创工品汇-官网|广州南创 | 金环宇|金环宇电线|金环宇电缆|金环宇电线电缆|深圳市金环宇电线电缆有限公司|金环宇电缆集团 | 北京发电车出租-发电机租赁公司-柴油发电机厂家 - 北京明旺盛安机电设备有限公司 | 【北京写字楼出租_写字楼租赁_办公室出租网/出售】-远行地产官网 | 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 | 帽子厂家_帽子工厂_帽子定做_义乌帽厂_帽厂_制帽厂_帽子厂_浙江高普制帽厂 | 仿清水混凝土_清水混凝土装修_施工_修饰_保护剂_修补_清水混凝土修复-德州忠岭建筑装饰工程 | 散热器-电子散热器-型材散热器-电源散热片-镇江新区宏图电子散热片厂家 | 卫浴散热器,卫浴暖气片,卫生间背篓暖气片,华圣格浴室暖气片 | 神马影院-实时更新秒播| 冷却塔厂家_冷却塔维修_冷却塔改造_凉水塔配件填料公司- 广东康明节能空调有限公司 | 团建-拓展-拓展培训-拓展训练-户外拓展训练基地[无锡劲途] | 手持式浮游菌采样器-全排二级生物安全柜-浙江孚夏医疗科技有限公司 | 郑州爱婴幼师学校_专业幼师培训_托育师培训_幼儿教育培训学校 | 四合院设计_四合院装修_四合院会所设计-四合院古建设计与建造中心1 |