久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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'>

                          主站蜘蛛池模板: 国产成人91| 免费福利在线观看 | 天天网综合 | 国 产 黄 色 大 片 | 国产精品一区在线 | 999久久久精品 | 久久99九九 | 黄色三级免费 | 网站毛片 | 日本成人久久 | 欧美日韩亚洲天堂 | 亚洲国产第一页 | 天天拍天天干 | 国产九九热 | av网页在线观看 | 欧美视频一区二区三区 | 99久久国产视频 | 亚洲精品91 | 欧美一级做性受免费大片免费 | 在线观看日韩 | 人人综合网 | 成人激情视频网 | 欧美美女一区二区 | 91日韩欧美 | 久久久黄色片 | 中文字幕免费观看 | 午夜国产在线观看 | 欧美一区二区三 | 麻豆精品国产 | 久久久久国产精品夜夜夜夜夜 | 久久综合一区 | av一级在线 | 91福利在线观看 | 国产亚洲欧美在线 | 国产精品国产三级国产 | 精品久久久久久久 | 欧洲色综合 | 久久精品欧美 | 中文字幕日韩一区 | 日本青青草| 日韩视频免费大全中文字幕 |