Dart Documentationchrome.devtoolsChromeDevtoolsInspectedWindow

ChromeDevtoolsInspectedWindow class

Use the chrome.devtools.inspectedWindow API to interact with the inspected window: obtain the tab ID for the inspected page, evaluate the code in the context of the inspected window, reload the page, or obtain the list of resources within the page.

class ChromeDevtoolsInspectedWindow extends ChromeApi {
 static final JsObject _devtools_inspectedWindow = chrome['devtools']['inspectedWindow'];

 ChromeDevtoolsInspectedWindow._();

 bool get available => _devtools_inspectedWindow != null;

 /**
  * The ID of the tab being inspected. This ID may be used with chrome.tabs.*
  * API.
  */
 int get tabId => _devtools_inspectedWindow['tabId'];

 /**
  * Evaluates a JavaScript expression in the context of the main frame of the
  * inspected page. The expression must evaluate to a JSON-compliant object,
  * otherwise an exception is thrown.
  * 
  * [expression] An expression to evaluate.
  * 
  * Returns:
  * [result] The result of evaluation.
  * [isException] Set if an exception was caught while evaluating the
  * expression.
  */
 Future<EvalResult> eval(String expression) {
   if (_devtools_inspectedWindow == null) _throwNotAvailable();

   var completer = new ChromeCompleter<EvalResult>.twoArgs(EvalResult._create);
   _devtools_inspectedWindow.callMethod('eval', [expression, completer.callback]);
   return completer.future;
 }

 /**
  * Reloads the inspected page.
  */
 void reload([DevtoolsInspectedWindowReloadParams reloadOptions]) {
   if (_devtools_inspectedWindow == null) _throwNotAvailable();

   _devtools_inspectedWindow.callMethod('reload', [jsify(reloadOptions)]);
 }

 /**
  * Retrieves the list of resources from the inspected page.
  * 
  * Returns:
  * The resources within the page.
  */
 Future<List<Resource>> getResources() {
   if (_devtools_inspectedWindow == null) _throwNotAvailable();

   var completer = new ChromeCompleter<List<Resource>>.oneArg((e) => listify(e, _createResource));
   _devtools_inspectedWindow.callMethod('getResources', [completer.callback]);
   return completer.future;
 }

 /**
  * Fired when a new resource is added to the inspected page.
  */
 Stream<Resource> get onResourceAdded => _onResourceAdded.stream;

 final ChromeStreamController<Resource> _onResourceAdded =
     new ChromeStreamController<Resource>.oneArg(_devtools_inspectedWindow, 'onResourceAdded', _createResource);

 /**
  * Fired when a new revision of the resource is committed (e.g. user saves an
  * edited version of the resource in the Developer Tools).
  */
 Stream<OnResourceContentCommittedEvent> get onResourceContentCommitted => _onResourceContentCommitted.stream;

 final ChromeStreamController<OnResourceContentCommittedEvent> _onResourceContentCommitted =
     new ChromeStreamController<OnResourceContentCommittedEvent>.twoArgs(_devtools_inspectedWindow, 'onResourceContentCommitted', _createOnResourceContentCommittedEvent);

 void _throwNotAvailable() {
   throw new UnsupportedError("'chrome.devtools.inspectedWindow' is not available");
 }
}

Extends

ChromeApi > ChromeDevtoolsInspectedWindow

Properties

final bool available #

Returns true if the API is available. The common causes of an API not being avilable are:

  • a permission is missing in the application's manifest.json file
  • the API is defined on a newer version of Chrome then the current runtime
docs inherited from ChromeApi
bool get available => _devtools_inspectedWindow != null;

final Stream<Resource> onResourceAdded #

Fired when a new resource is added to the inspected page.

Stream<Resource> get onResourceAdded => _onResourceAdded.stream;

final Stream<OnResourceContentCommittedEvent> onResourceContentCommitted #

Fired when a new revision of the resource is committed (e.g. user saves an edited version of the resource in the Developer Tools).

Stream<OnResourceContentCommittedEvent> get onResourceContentCommitted => _onResourceContentCommitted.stream;

final int tabId #

The ID of the tab being inspected. This ID may be used with chrome.tabs.* API.

int get tabId => _devtools_inspectedWindow['tabId'];

Methods

Future<EvalResult> eval(String expression) #

Evaluates a JavaScript expression in the context of the main frame of the inspected page. The expression must evaluate to a JSON-compliant object, otherwise an exception is thrown.

expression An expression to evaluate.

Returns: result The result of evaluation. isException Set if an exception was caught while evaluating the expression.

Future<EvalResult> eval(String expression) {
 if (_devtools_inspectedWindow == null) _throwNotAvailable();

 var completer = new ChromeCompleter<EvalResult>.twoArgs(EvalResult._create);
 _devtools_inspectedWindow.callMethod('eval', [expression, completer.callback]);
 return completer.future;
}

Future<List<Resource>> getResources() #

Retrieves the list of resources from the inspected page.

Returns: The resources within the page.

Future<List<Resource>> getResources() {
 if (_devtools_inspectedWindow == null) _throwNotAvailable();

 var completer = new ChromeCompleter<List<Resource>>.oneArg((e) => listify(e, _createResource));
 _devtools_inspectedWindow.callMethod('getResources', [completer.callback]);
 return completer.future;
}

void reload([DevtoolsInspectedWindowReloadParams reloadOptions]) #

Reloads the inspected page.

void reload([DevtoolsInspectedWindowReloadParams reloadOptions]) {
 if (_devtools_inspectedWindow == null) _throwNotAvailable();

 _devtools_inspectedWindow.callMethod('reload', [jsify(reloadOptions)]);
}