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'>

                          主站蜘蛛池模板: 艾默生变频器,艾默生ct,变频器,ct驱动器,广州艾默生变频器,供水专用变频器,风机变频器,电梯变频器,艾默生变频器代理-广州市盟雄贸易有限公司官方网站-艾默生变频器应用解决方案服务商 | 陶氏道康宁消泡剂_瓦克消泡剂_蓝星_海明斯德谦_广百进口消泡剂 | 科箭WMS仓库管理软件-TMS物流管理系统-科箭SaaS云服务 | 电伴热系统施工_仪表电伴热保温箱厂家_沃安电伴热管缆工业技术(济南)有限公司 | 英超直播_英超免费在线高清直播_英超视频在线观看无插件-24直播网 | 模型公司_模型制作_沙盘模型报价-中国模型网 | 加热制冷恒温循环器-加热制冷循环油浴-杭州庚雨仪器有限公司 | 红外光谱仪维修_二手红外光谱仪_红外压片机_红外附件-天津博精仪器 | 采暖炉_取暖炉_生物质颗粒锅炉_颗粒壁炉_厂家加盟批发_烟台蓝澳采暖设备有限公司 | 武汉高低温试验箱_恒温恒湿试验箱厂家-武汉蓝锐环境科技有限公司 | 油漆辅料厂家_阴阳脚线_艺术漆厂家_内外墙涂料施工_乳胶漆专用防霉腻子粉_轻质粉刷石膏-魔法涂涂 | 汕头市盛大文化传播有限公司,www.11400.cc | 阴离子_阳离子聚丙烯酰胺厂家_聚合氯化铝价格_水处理絮凝剂_巩义市江源净水材料有限公司 | 定制/定做冲锋衣厂家/公司-订做/订制冲锋衣价格/费用-北京圣达信 | elisa试剂盒价格-酶联免疫试剂盒-猪elisa试剂盒-上海恒远生物科技有限公司 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 爆炸冲击传感器-无线遥测传感器-航天星百科 | 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 联系我们老街华纳娱乐公司官网19989979996(客服) | POM塑料_PBT材料「进口」聚甲醛POM杜邦原料、加纤PBT塑料报价格找利隆塑料 | 集菌仪厂家_全封闭_封闭式_智能智能集菌仪厂家-上海郓曹 | 对夹式止回阀厂家,温州对夹式止回阀制造商--永嘉县润丰阀门有限公司 | 江苏皓越真空设备有限公司 | 仪器仪表网 - 永久免费的b2b电子商务平台 | 济南网站建设|济南建网站|济南网站建设公司【济南腾飞网络】【荐】 | 爆破器材运输车|烟花爆竹运输车|1-9类危险品厢式运输车|湖北江南专用特种汽车有限公司 | 河南15年专业网站建设制作设计,做网站就找郑州启凡网络公司 | H型钢切割机,相贯线切割机,数控钻床,数控平面钻,钢结构设备,槽钢切割机,角钢切割机,翻转机,拼焊矫一体机 | 上海小程序开发-小程序制作-上海小程序定制开发公司-微信商城小程序-上海咏熠 | RO反渗透设备_厂家_价格_河南郑州江宇环保科技有限公司 | 泰兴市热钻机械有限公司-热熔钻孔机-数控热熔钻-热熔钻孔攻牙一体机 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 磁力去毛刺机_去毛刺磁力抛光机_磁力光饰机_磁力滚抛机_精密金属零件去毛刺机厂家-冠古科技 | 比士亚-专业恒温恒湿酒窖,酒柜,雪茄柜的设计定制 | 电动卫生级调节阀,电动防爆球阀,电动软密封蝶阀,气动高压球阀,气动对夹蝶阀,气动V型调节球阀-上海川沪阀门有限公司 | 武汉刮刮奖_刮刮卡印刷厂_为企业提供门票印刷_武汉合格证印刷_现金劵代金券印刷制作 - 武汉泽雅印刷有限公司 | 中医治疗皮肤病_潍坊银康医院「山东」重症皮肤病救治平台 | 顺景erp系统_erp软件_erp软件系统_企业erp管理系统-广东顺景软件科技有限公司 | 全自动真空上料机_粉末真空上料机_气动真空上料机-南京奥威环保科技设备有限公司 | AR开发公司_AR增强现实_AR工业_AR巡检|上海集英科技 |