1

I am connected to Chrome (34.0.1847.132) via the Remote Debugging Protocol, and I have successfully enabled runtime and console debugging. I can send Chrome messages and will get the responses back.

Now, I'd like to inspect the properties of a certain JavaScript variable in the current page. So, in my HTML page, I have the following statement in a script tag:

window.foo = {
  'bar' : 'baz'
}

I can query the property with window.foo.bar from the console in Chrome itself, but I cannot do it via remote debugging, since I receive an error.

To get the property, I send this JSON message to the WebSocket:

{
  :method => "Runtime.getProperties", 
  :params => {
    :objectId => "window.foo.bar"
  }, 
  "id"=>2
}

And I get the response:

{
    "error" => {
           "code" => -32000,
        "message" => "Inspected frame has gone"
    },
       "id" => 2
}

Similarly, if I try to Runtime.evaluate the expression window.foo.bar, I get:

{
    "result" => {
           "result" => {
                   "type" => "object",
               "objectId" => "{\"injectedScriptId\":1,\"id\":1}",
              "className" => "TypeError",
            "description" => "TypeError: Cannot read property 'bar' of undefined"
        },
        "wasThrown" => true
    },
        "id" => 2
}

What would cause the "inspected frame" to be gone? What is that, even? Or is the objectId something completely different?

How do I access the property of a JavaScript variable then?

2
  • Can you specify keep alive interval? Commented May 7, 2014 at 14:13
  • It's not a problem of the web socket connection being dropped. It stays open all the time. In fact, I can send commands back and forth without issues, just the ` Runtime.getProperties` makes the inspected frame "gone". Commented May 7, 2014 at 14:16

3 Answers 3

2

Runtime.evaluate and Runtime.callFunctionOn return a RemoteObject that has objectId field, in case the expression has evaluated into an Object. Further object identifiers will be returned for the object's properties if you enumerate them via Runtime.getProperties.

Sign up to request clarification or add additional context in comments.

Comments

1

What's important to know is that Runtime.evaluate accesses at the level of window, so if you want to access window.document, you need document as an expression.

Doing this worked, in the end:

window.document.foo = "bar"

And in the request:

{
  :method => "Runtime.evaluate", 
  :params => {
    :expression => "document.foo"
  },
  "id" => 1
}

You may want to set returnByValue in the parameters to true if you want to access object properties and such.

2 Comments

But window.window === window?
Yes, I know. But if I set window.foo, I cannot query foo, and window.foo neither. Don't ask me why this is.
0

Take a look at source search for "Inspected frame has gone" it might give you some insight on what is happening. This does look like a good candidate.

void InspectorRuntimeAgent::getProperties(ErrorString* errorString, const String& objectId, const bool* const ownProperties, RefPtr<InspectorArray>* result)
{
    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForObjectId(objectId);
    if (injectedScript.hasNoValue()) {
        *errorString = "Inspected frame has gone";
    return;
    }
    injectedScript.getProperties(errorString, objectId, ownProperties ? *ownProperties : false, result);
}

You are passing window.foo.bar as const String& objectId.
I would assume it cannot find it, as you must be hitting injectedScript.hasNoValue().

8 Comments

Thanks, but this is more of a comment than an answer, really. It just raises more questions.. it seems like it's looking for some injected script? What would that be?
You are passing window.foo.bar as const String& objectId? I would assume it cannot find it. Try "foo.bar" instead
window.foo.bar, like mentioned in the question. But perhaps it should be something completely different -- I don't know, I cannot tell from the documentation.
I have edited my previous comment cause it was stupid, sorry about that. Please try foo.bar without window.
No dice, same error message. (The connection is kept alive though, afterwards.)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.