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

在 chrome 的控制臺中添加自定義功能

adding custom functionality into chrome#39;s console(在 chrome 的控制臺中添加自定義功能)
本文介紹了在 chrome 的控制臺中添加自定義功能的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

是否可以在 google-chrome 中擁有始終在控制臺中可用的自定義功能(無論加載什么頁面)?例如,我想要一個名為 echo 的函數,它只是 console.log 的一個包裝器.這只是節省了一些輸入,但稍后我可能想創建一些有用的調試功能.

Is it possible to have custom functions in google-chrome that will be always available in console (no matter what page is loaded)? For instance, I would like to have a function called echo that would be just a wrapper around console.log. This just saves a bit of typing but later I might want to create some useful debug functionality.

推薦答案

這很容易實現.您需要創建一個內容腳本.該腳本將被注入任何頁面并創建一些您將在控制臺中使用的必要全局函數.最具挑戰性的部分是如何使這些自定義內容腳本函數成為您實際 window 對象的一部分,因為通常您無法從其余部分訪問您在內容腳本中定義的函數或變量不在內容腳本中的 javascript 代碼.內容腳本在所謂的隔離環境中運行.

Well it's pretty easy to accomplish. What you need is to create a content script. This script would be injected in any page and create some necessary global functions you would use in your console. The most challenging part is how to make those custom content scrtipt functions to be part of your actual window object, because normally you can't access functions or variables you define in your content script from the rest of the javascript code which is not within content script. Content scripts run in so-called isolated enviroment.

內容腳本在稱為孤立世界的特殊環境中執行.他們可以訪問被注入頁面的 DOM,但不能訪問頁面創建的任何 JavaScript 變量或函數.它查看每個內容腳本,就好像它正在運行的頁面上沒有執行其他 JavaScript.反過來也是如此:頁面上運行的 JavaScript 不能調用任何函數或訪問任何由內容腳本定義的變量.

Content scripts execute in a special environment called an isolated world. They have access to the DOM of the page they are injected into, but not to any JavaScript variables or functions created by the page. It looks to each content script as if there is no other JavaScript executing on the page it is running on. The same is true in reverse: JavaScript running on the page cannot call any functions or access any variables defined by content scripts.

但是有一些奇特的解決方法.
你定義你的清單文件如下:

But there are fancy workaround.
You define your manifest file as follows:

ma??nifest.json

{
    "name": "Content script",
    "version": "0.1",
    "manifest_version": 2,
    "content_scripts": [{
        "matches": ["http://*/*"],
        "js": ["console.js"]
    }]
}

還有你的內容腳本:

console.js

function customConsole() {
    window.myNewFunction = function() {
        console.log("Hello I'm available from console.");
    };
}

var script = document.createElement('script'),
    code   = document.createTextNode('(' + customConsole + ')();');
script.appendChild(code);
(document.body || document.head || document.documentElement).appendChild(script);

因此,您將新函數指定為全局函數,以便您可以在 console 中使用它們.
也看看這個 post

So you specify your new functions as global functions so that you could use them in console.
Also take a look at this post

這篇關于在 chrome 的控制臺中添加自定義功能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 999热在线视频| 国产成人啪免费观看软件 | 色综合久久久久 | 日韩一区二区三区视频 | 在线免费视频一区 | 欧美一区二区三区在线 | 日韩欧美黄色 | 成人免费视频网站 | 一区精品国产欧美在线 | 日韩一区二区三区视频 | 嫩呦国产一区二区三区av | 91免费在线视频 | 国产中文视频 | 亚洲精品中文在线 | 国产精品视频网站 | 天堂资源最新在线 | 亚洲免费在线观看 | 国产一区二区三区在线免费 | 日韩在线免费视频 | 午夜爽爽男女免费观看hd | 久久精品免费 | 亚洲97 | 国产精品久久久亚洲 | 天天人人精品 | 自拍视频国产 | 欧美日韩国产精品一区二区 | 亚洲国产精品第一区二区 | 日韩精品中文字幕一区二区三区 | 亚洲视频免费 | 最新黄色毛片 | 久久日韩粉嫩一区二区三区 | 午夜精品一区二区三区在线 | 亚洲欧美中文日韩在线v日本 | 一级片在线观看视频 | 久久久亚洲精品视频 | 日韩福利 | 亚洲性视频在线 | 91视频国产精品 | 亚洲444eee在线观看 | 日韩精品1区2区3区 爱爱综合网 | 亚洲性人人天天夜夜摸 |