chrome 開發工具_我最喜歡的Chrome開發工具提示和技巧

chrome 開發工具

Chrome Developer Tools are a super powerful suite of tools for developing web applications. They can do so much, from very basic operations like traversing the DOM, to checking out network requests or even profiling your application's performance.

Chrome Developer Tools是用于開發Web應用程序的超強大工具套件。 他們可以做很多事情,從遍歷DOM等非常基本的操作到簽出網絡請求甚至分析應用程序的性能。

Among the big, everyday features they enable, there are quite a lot of gems to be found if you look deep enough. Features that might save you a click or two – and isn't that what we're all about here?

在它們啟用的日常功能中,如果您看起來足夠深,就會發現很多寶石。 可以節省您一兩次點擊的功能-難道不是我們在這里所擁有的一切嗎?

控制臺中的jQuery風格DOM查詢 (jQuery style DOM queries in the console)

jQuery is awesome. It has ruled the web for over a decade, and some statistics state that more than 70% of the most popular web pages in the world run some version of jQuery. That's crazy for a library dating all the way back to 2006.

jQuery很棒。 它已經統治了網絡十多年,一些統計數據表明,世界上超過70%的最受歡迎網頁都運行某種版本的jQuery。 對于一個可追溯到2006年的圖書館來說,這是很瘋狂的。

The most popular API jQuery provides is the $, used for selecting DOM elements. The Chrome dev tools console allows you to make use of that $ selector, and more. Under the hood, $ is an alias to document.querySelector().

jQuery最受歡迎的API是$ ,用于選擇DOM元素。 Chrome開發者工具控制臺可讓您使用$選擇器等。 在幕后, $document.querySelector()的別名。

For example, if you want to simulate a click on an element you can do:

例如,如果要模擬元素的單擊,可以執行以下操作:

Similarly, $$ is an alias to document.querySelectorAll():

同樣, $$document.querySelectorAll()的別名:

There are a few more tricks up the $ sleeve. Sometimes, a selector might be too complicated to write by heart, or you just don't know a selector specific enough. If you pick an element in the Elements tab you can retrieve it with the $0 variable in the console:

$袖子還有一些技巧。 有時候,選擇器可能太復雜而無法用心書寫,或者您只是對選擇器不夠了解。 如果在“元素”選項卡中選擇一個元素,則可以在控制臺中使用$0變量進行檢索:

The console goes even further, allowing us to access not only the last selection, but the last 5, in order. The selections are exposed through the $0 - $4 variables:

控制臺走得更遠,使我們不僅可以訪問最后一個選擇,而且可以依次訪問最后五個。 通過$0 $4變量公開選擇內容:

復制元素的屬性 (Copying an element's properties)

The elements tab is a really useful tab. It stores our website DOM tree, it allows us to see the CSS applied to each element, and we can make changes to elements on the fly from it.

元素選項卡是一個非常有用的選項卡。 它存儲了我們的網站DOM樹,它使我們能夠看到應用于每個元素CSS,并且我們可以從中動態更改元素。

A really cool trick I've found is the ability to copy properties of an element (and not only properties) from the context menu.

我發現一個非常酷的技巧是能夠從上下文菜單中復制元素的屬性(不僅是屬性)。

For example, you can copy an element's selector:

例如,您可以復制元素的選擇器:

This selector might not be specific enough, or too specific for production, but should make your life a little easier when debugging.

這個選擇器可能不夠具體,或者對于生產來說太具體了,但是在調試時應該會使您的生活更輕松一些。

As you can see in the previous gif, the copy context menu hides a few more nifty things you can copy. You can copy the element's styles, JS path (document.querySelector(SELECTOR)) or XPath.

正如您在上一個gif中看到的那樣,復制上下文菜單隱藏了一些可以復制的漂亮東西。 您可以復制元素的樣式,JS路徑( document.querySelector(SELECTOR) )或XPath。

過濾網絡請求 (Filtering network requests)

Sometimes, you work on a page that has a lot of requests. I mean, A LOT.

有時,您在一個有很多請求的頁面上工作。 我的意思是,很多。

Working your way through all those requests can be difficult when you look for something specific. Thankfully, you can very easily filter the requests.

當您尋找特定的內容時,很難解決所有這些請求。 幸運的是,您可以非常輕松地過濾請求。

The filter toolbar has quick toggles for various request types, such as XHR/Fetch, stylesheets, JS scripts, images and more:

過濾器工具欄可快速切換各種請求類型,例如XHR / Fetch,樣式表,JS腳本,圖像等:

If you need to be even more specific, or so that you might find it quicker, you can just write a filter criteria in the filter input right above the toolbar to search in the requests' names:

如果您需要更加具體,或者為了更快地找到它,可以在工具欄上方的filter輸入中編寫過濾條件,以搜索請求的名稱:

模擬不同的網絡速度 (Emulating different network speeds)

Using the Network tab again we can test our site in various internet speeds. The default preset is online, and you'll enjoy the full bandwidth of your internet connection.

再次使用“ Network選項卡,我們可以各種互聯網速度測試我們的網站。 默認預設為online ,您將享受互聯網連接的全部帶寬。

Besides online, there are a few more presets available: Fast 3G, Slow 3G and offline, which vary in upload speed, download speed and latency. If you need to emulate a different, more exotic speed, you can add your own profile through the Add... button:

除了online ,還有更多可用的預設: Fast 3GSlow 3Goffline ,它們的上載速度,下載速度和延遲有所不同。 如果需要模擬另一種更奇特的速度,可以通過“ Add...按鈕Add...自己的配置文件:

在控制臺中使用實時表達式 (Using Live Expressions in console)

What are Live Expressions?

什么是Live Expressions

Live Expressions are expressions which evaluate constantly at the top of your console. Say, you want to track a variable's value over time. You can log it over and over and over again:

Live Expressions是在控制臺頂部不斷求值的表達式。 假設您要跟蹤一段時間內變量的值。 您可以一遍又一遍地記錄它:

With Live Expressions, you can focus on your code, and let Chrome do the monitoring:

借助Live Expressions ,您可以專注于代碼,并讓Chrome進行監視:

This applies for variables defined both in the console and in a script.

這適用于在控制臺和腳本中定義的變量。

模擬不同的設備 (Emulating different devices)

Those of us working on responsive applications know the feeling where you work really hard to make a beautiful layout, only to see it misbehave on devices with different resolutions.

我們那些從事響應式應用程序工作的人都知道,您很難在哪里做出漂亮的布局,只是發現它在不同分辨率的設備上表現不佳。

I'm not here to tell you about media queries, but rather a convenient way to test that they work.

我不是在這里向您介紹媒體查詢,而是一種方便的方法來測試它們是否有效。

When you click on the button that looks like a tablet and a phone, you'll see that your browser's viewport changes to reflect a different device's dimensions.

單擊看起來像平板電腦和電話的按鈕時,您會看到瀏覽器的視口發生變化以反映其他設備的尺寸。

You can choose a device from a list of presets containing various popular devices, such as iPhone X, iPad Pro, Pixel 2, Pixel 2 XL and more. The list is admittedly a bit outdated, but I think it's good enough for most cases.

您可以從包含各種常用設備的預設列表中選擇一種設備,例如iPhone X,iPad Pro,Pixel 2,Pixel 2 XL等。 列表當然已經過時了,但是我認為對于大多數情況來說已經足夠了。

If you can't find a device that fits your needs, you can set a custom resolution. As you can see, I've set a custom resolution to emulate a OnePlus 6 (which is my daily driver).

如果找不到適合您需求的設備,則可以設置自定義分辨率。 如您所見,我已經設置了自定義分辨率來模擬OnePlus 6(這是我的日常驅動程序)。

強制元素的狀態 (Forcing an element's state)

Have you ever faced a situation where you wanted to play with an element's :hover-specific CSS, but every time you moved your mouse to the styles section in the dev tools the element was no longer hovered?

您是否曾經遇到過要使用元素的:hover特定CSS的情況,但是每次將鼠標移至開發工具中的styles部分時,該元素就不再懸停了嗎?

Well, Chrome dev tools exposes a nice way to lock an element's state, so you can fiddle with its properties with peace. This way you can quickly toggle an element's :active, :hover, :focus, :focus-within and :visited properties:

不錯,Chrome開發人員工具提供了一種鎖定元素狀態的好方法,因此您可以安心地使用它的屬性。 這樣,您可以快速切換元素的:active:hover:focus:focus-within:visited屬性:

Those are my tips and tricks I think everyone can benefit from. Thank you for reading!

這些是我認為每個人都可以從中受益的提示和技巧。 感謝您的閱讀!

This article was previously published on my blog: dorshinar.me. If you want to read more content, you can check out my blog as it would mean a lot to me.

該文章先前已發布在我的博客dorshinar.me上 。 如果您想內容,可以查看我的博客,因為這對我來說意義重大。

Buy Me a Coffee at ko-fi.com

翻譯自: https://www.freecodecamp.org/news/awesome-chrome-dev-tools-tips-and-tricks/

chrome 開發工具

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390428.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390428.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390428.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

三十四 Python分布式爬蟲打造搜索引擎Scrapy精講—scrapy信號詳解

信號一般使用信號分發器dispatcher.connect(),來設置信號,和信號觸發函數,當捕獲到信號時執行一個函數 dispatcher.connect()信號分發器,第一個參數信號觸發函數,第二個參數是觸發信號, 以下是各種信號 sig…

1713. 得到子序列的最少操作次數

給你一個數組 target ,包含若干 互不相同 的整數,以及另一個整數數組 arr ,arr 可能 包含重復元素。 每一次操作中,你可以在 arr 的任意位置插入任一整數。比方說,如果 arr [1,4,1,2] ,那么你可以在中間添…

CVE-2018-1000136:Electron nodeIntegration繞過漏洞

1周前,研究人員發現一個影響Electron所有版本的漏洞,利用該漏洞可以開啟nodeIntegration,這可能會造成遠程代碼執行。Electron是一個使用JavaScript,HTML和CSS等Web技術創建原生程序的框架,它負責比較難搞的部分,而用戶…

bash腳本 文件_如何使用Bash腳本來管理從AWS S3存儲桶下載和查看文件

bash腳本 文件As you can read in this article, I recently had some trouble with my email server and decided to outsource email administration to Amazons Simple Email Service (SES). 正如您在本文中所讀到的 ,最近我的電子郵件服務器遇到了一些麻煩&…

rsync(六)命令中文手冊

rsync(1) rsync(1)名稱rsync - 一個快速、多功能的遠程(和本地)文件拷貝工具摘要Local: rsync [OPTION...] SRC... [DEST]Access via remote shell:Pull: rsync [OPTION...] [USE…

NFS共享存儲服務部署

服務端部署 1、檢查服務器上是否已安裝nfs及rpc,沒有則需要安裝檢查rpm -qa rpcbind nfs-utils安裝(已安裝略過)yum install -y rpcbind nfs-utils################################################################2、編寫nfs的配置文件cat…

區塊鏈運作機制_什么是區塊鏈及其運作方式?

區塊鏈運作機制If youre interested in technology, theres a good chance you’ve probably heard the terms Bitcoin, Crypto, Ethereum, or even "distributed, decentralized ledgers."如果您對技術感興趣,那么您很有可能已經聽說過比特幣&#xff0c…

敏捷管理之績效考核方案

前段時間,公司簽了年終獎確認。覺得公司發放年終獎完全是憑主觀發放,沒有事實依據,由此產生了對如何發放年終獎的一些想法。 獎金發放作為激勵員工最直接的手段,往往也是讓管理人員最難抉擇的,而且很多公司&#xff0c…

序言

為什么要寫這篇文章? 說起架構,剛入行的新人覺得是高大上的技術,有工作經驗的一些人又覺得是虛無縹緲的東西,不能落實。具體有用沒用,我不給答案,想通過寫這么一個例子來還原場景,讓讀者自己判斷…

kotlin編程語言_Kotlin初學者編程基礎

kotlin編程語言什么是Kotlin? (What is Kotlin?) Kotlin is a programming language developed by Jetbrains, the company behind some of the world’s most popular IDEs like IntelliJ and Pycharm.Kotlin是Jetbrains開發的一種編程語言,該公司是In…

記一個蒟蒻的絕望

感覺現在…… 怎么講,心挺冷的。 今天一月五號了。距離省選,時間好短啊。 我還有那么多東西不懂。甚至聽都沒聽說過。 等到真正去省選的時候,我可能跟現在一樣,什么都不會。 我的名字能不能被看到都不知道。哈,還進隊呢…

671. 二叉樹中第二小的節點

給定一個非空特殊的二叉樹,每個節點都是正數,并且每個節點的子節點數量只能為 2 或 0。如果一個節點有兩個子節點的話,那么該節點的值等于兩個子節點中較小的一個。 更正式地說,root.val min(root.left.val, root.right.val) 總…

CentOS查詢端口占用和清除端口占用的程序

1、查詢端口號占用,根據端口查看進程信息 [rootserver2 ~]# lsof -i:80COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEhttpd 5014 root 3u IPv4 14346 TCP server2:http (LISTEN)2、根據進程號查看進程對應的可執行程序 ps -f -p 進程號# p…

Android基礎夯實--你了解Handler有多少?

概述 對于剛入門的同學來說,往往都會對Handler比較迷茫,到底Handler是個什么樣的東西。當然,可能對于一些有工作經驗的工程師來說,他們也不一定能很準確地描述,我們來看下API的介紹。 Handler是用來結合線程的消息隊列…

spring與springBoot不同之處

( 1)遵循“習慣優于配置”的原則,使用Spring Boot只需要很少的配置,大部分的時候我們直接使用默認的配置即可; (2)項目快速搭建,可以無需配置的自動整合第三方的框架; (3…

sketch-a-net_Adobe XD,Sketch,Figma,InVision-如何在2020年選擇最佳設計軟件

sketch-a-netComparing Adobe XD vs Sketch vs Figma vs InVision studio is a very common topic among designers who are looking for the best design software. 在尋求最佳設計軟件的設計師中,比較Adobe XD,Sketch,Figma和InVision Stud…

merge intervals(合并間隔)

Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]. 題目沒有說所有間隔的start是依次增加的。所以,為了方便討論,我們要將所有間隔按照start升序排列。因…

劍指 Offer 49. 丑數

我們把只包含質因子 2、3 和 5 的數稱作丑數(Ugly Number)。求按從小到大的順序的第 n 個丑數。 示例: 輸入: n 10 輸出: 12 解釋: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 個丑數。 說明: 1 是丑數。n 不超過1690。 解題思路 使用小根堆&#xf…

維護舊項目_為什么您的舊版軟件難以維護-以及如何處理。

維護舊項目Believe it or not, some organizations still rely on legacy software to carry out operations even though newer and more versatile options are available. We know that “old is gold”, but legacy applications cannot glitter forever. As such, these o…

python--內置函數

內置函數現在python一共為我們提供了68個內置函數,講述過程:一、其他中的12個 (一)執行 字符串 類型代碼的執行 1 eval執行有意義的字符串 ,有返回值 print(eval(12))print(eval("print(美麗)")) #美麗 2 ex…