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

      為什么這段代碼不起作用?我正在創(chuàng)建一個(gè) 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(為什么這段代碼不起作用?我正在創(chuàng)建一個(gè) Firefox 擴(kuò)展,但代碼沒有運(yùn)行.但是

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

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

                問題描述

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

                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.

                當(dāng)擴(kuò)展程序加載時(shí)它沒有顯示任何錯(cuò)誤,它似乎只是不會運(yùn)行

                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 方法不起作用.僅當(dāng)我將代碼粘貼到控制臺時(shí)才有效.

                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 代碼復(fù)制并粘貼到 https://reactjs.org(這是一個(gè) 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.

                我不知道為什么這段代碼只有在控制臺粘貼時(shí)才會運(yùn)行

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

                推薦答案

                內(nèi)容腳本在隔離的 JavaScript 環(huán)境中運(yùn)行,這意味著 window 及其內(nèi)容與頁面隔離,因此當(dāng)您修改它時(shí),您只修改內(nèi)容腳本的版本.

                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 腳本在頁面上下文中運(yùn)行代碼:說明.

                它不適用于受嚴(yán)格的 Content-Security-Policy (CSP) 保護(hù)的頁面,該 CSP 會阻止腳本執(zhí)行,因此在為 Firefox 編寫擴(kuò)展時(shí),我們應(yīng)該改用 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.

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

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

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調(diào)用完成)
                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標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                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 部分內(nèi)容)

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

                          主站蜘蛛池模板: h视频在线免费 | 超碰在线97国产 | 午夜不卡福利视频 | 蜜臀久久 | 欧美在线视频免费 | 国产乱性| 日韩一区二区三区视频 | 中文字幕高清 | 91精品国产综合久久久久 | 国内精品久久久久久 | 国产成人久久 | 免费观看一级毛片视频 | 成人免费一区二区三区牛牛 | 中文字幕1区2区 | 一区二区三区回区在观看免费视频 | 色婷婷综合网 | 亚洲国产一区在线 | 国产高清免费 | 人成精品| 91精品国产色综合久久 | 国产精品美女久久久久aⅴ国产馆 | 9久9久| 国产一区二区久久 | 国产午夜精品一区二区三区 | 欧美激情综合网 | 99reav| 欧美激情精品久久久久久免费 | 日韩一区二区免费视频 | 久久伊人精品 | 国产成人精品a视频 | 国产在线观 | 91久久| 亚洲不卡在线观看 | 91久久网站 | 亚州精品天堂中文字幕 | 亚洲国产成人在线视频 | 日韩精品免费在线观看 | 亚洲精品久久久一区二区三区 | 国产欧美在线一区二区 | 网址黄 | 国产农村妇女精品一区 |