firefox-devtools / extension-examples

DevTools extension examples
Mozilla Public License 2.0
27 stars 7 forks source link

Inspector protocol error #2

Closed janodvarko closed 7 years ago

janodvarko commented 7 years ago

This issue is related to 'console' example.

I am getting the following error when evaluating window expression in the inspected window.

Inspector protocol error: TypeError: cyclic object value

The related code is here: https://github.com/devtools-html/extension-examples/blob/master/console/panel.js#L18

STR: 1) Install the Console example 2) Open the Toolbox and select 'MyConsole' panel 3) Type window in the command line and press Enter key 4) The result says undefined and there is the aforementioned error

Honza

janodvarko commented 7 years ago

In order to see the error in the Browser console you can do the following:

chrome.devtools.inspectedWindow.eval(expr, (result, error) => {
  if (error) {
    console.log("error ", error);
  } else {
    console.log("result ", result);
  }
  appendLog(expr, result, error);
});
janodvarko commented 7 years ago

@rpl any tips?

Honza

rpl commented 7 years ago

@janodvarko yep, it is part of the expected behavior:

the inspectedWindow.eval returns the result of the evaluated code to the caller over the remote debugging protocol, if the eval result cannot be serialized to JSON, a protocol error have to be returned.

e.g. while chrome.devtools.inspectedWindow.eval("window", (result, error) => {}) will result into a protocol error, chrome.devtools.inspectedWindow.eval("window.location", (result, error) => {}) should work fine (because there is no cyclic object reference that prevents it to be serialized to JSON)

There are basically two kind of errors that can happens during a inspectedWindow.eval call:

More info on this behavior can be found in the related Chrome API docs: https://developer.chrome.com/extensions/devtools_inspectedWindow#method-eval

janodvarko commented 7 years ago

I see, thanks for the info! Honza