[英]Control Chrome Web Inspector in Javascript console?
Is there anyway to control the Chrome Web Inspector in the JavaScript console? 无论如何,是否可以在JavaScript控制台中控制Chrome Web Inspector?
For example, say I wanted to select an element (#test_element) in the "Elements" panel. 例如,假设我想在“元素”面板中选择一个元素(#test_element)。 Normally I right click on the element and choose "Inspect Element". 通常,我右键单击该元素,然后选择“检查元素”。
I'd like to do this in the JavaScript console, using something like: 我想在JavaScript控制台中执行以下操作:
webInspector.inspectElement("#test_element");
I'd like to be able to access the entire UI of the web inspector this way. 我希望能够以这种方式访问Web检查器的整个UI。 I'm open to using extensions for this as well. 我也愿意为此使用扩展。
Use inspect
for this purpose. 为此使用inspect
。 Since you want to use a selector, combine it with the console's $
alias for document.querySelector
. 由于要使用选择器,因此请将其与控制台的$
别名结合用于document.querySelector
。 If the page overrides $
, because it uses jQuery, use $$(selector)[0]
to get a reference to the DOM element (anything would do, as long as it's a reference to a DOM node). 如果页面重写$
,因为它使用jQuery,则使用$$(selector)[0]
获取对DOM元素的引用(只要它是对DOM节点的引用,任何操作都可以)。
From the Command Line Api Reference 从命令行Api参考
inspect(object)
Opens and selects the specified element or object in the appropriate panel: either the Elements panel for DOM elements and the Profiles panel for JavaScript heap objects. 在适当的面板中打开并选择指定的元素或对象:DOM元素的Elements面板和JavaScript堆对象的Profiles面板。
The following example opens the first child element of document.body in the Elements panel: 以下示例在“元素”面板中打开document.body的第一个子元素:
inspect(document.body.firstChild);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.