----
Debugger API serves as an alternate transport for Chrome's remote debugging protocol. Use debugger to attach to a tab, instrument its network interaction, debug JavaScript, mutate page's DOM and CSS, etc.
As of today, attaching to the tab by means of the debugger API and using embedded Chrome DevTools with that tab are mutually exclusive. If user invokes Chrome DevTools while extension is attached to the tab, debugging session is terminated. Extension can re-establish it later.
----I'm not sure why you say that, the API uses
chrome.experimental.debugger.attach(Debuggee target, string
requiredVersion, function callback)
and target is just tabId inside of an object.
In addition, I guess I was thrown of track by the remote debug
protocol, which never mentions tab id. It has a rich API so it
commands a lot of attention. So in my mind the debugger was 'attached'
to a tab and everything after that was within a tab.
> What
> are 'windows' in your case?
I call
chrome.windows.create(createData);
twice from background.html, then call the debugger.attach() in the result.
jjb
I don't know what you mean here. According to the doc page, the
|callback| above is only called if there is an error.
> I was talking
> about chrome.experimental.debugger.onEvent - that one has no notion of
> tabId.
When I wrote the code I did not think much about onEvent. I was trying
to decipher the relationship between chrome.experimental.debugger and
the remote protocol. So in my onEvent handler I immediately call
another method in an object organized around the remote protocol. I
assumed the tabId argument was just a convenience. After all I already
supplied the target tabId in the attach() call.
>
>> In addition, I guess I was thrown of track by the remote debug
>> protocol, which never mentions tab id. It has a rich API so it
>> commands a lot of attention. So in my mind the debugger was 'attached'
>> to a tab and everything after that was within a tab.
>
> That's pretty much the idea. chrome.experimental.debugger is just a
> transport for the protocol messages.
But unlike the socket protocol, this one is not bound to a tab on
creation. Hence my confusion.
jjb
The doc says:
----
callback
( optional function )
If an error occurs while attaching to the target, the callback
will be called with no arguments and chrome.extension.lastError will
be set to the error message.
---
There is no "else". I have to use the Debugger.debuggerWasEnabled
event to confirm the connection.
>
>> > I was talking
>> > about chrome.experimental.debugger.onEvent - that one has no notion of
>> > tabId.
>>
>> When I wrote the code I did not think much about onEvent. I was trying
>> to decipher the relationship between chrome.experimental.debugger and
>> the remote protocol. So in my onEvent handler I immediately call
>> another method in an object organized around the remote protocol.
>
> Well, this is a static dispatcher, you should care. My hope is that
> Chrome Extensions authors have learned this already (probably the hard
> way).
Well for what it's worth I am not a Chrome Extension author.
chrome.experimental.debugger was my first attempt.
jjb
>> Well, this is a static dispatcher, you should care. My hope is that
>> Chrome Extensions authors have learned this already (probably the hard
>> way).
>
> Well for what it's worth I am not a Chrome Extension author.
> chrome.experimental.debugger was my first attempt.
>
We had a similar concern while discussing the options to implement
chrome.devtools.* APIs: exposing interface to multiple possible
debuggees into a single background page (or, for that matter, any
extension page that shares global events) is inherently confusing. It
could possibly be addressed by using a debuggee-specific event object
(e.g. returned by an attach() call) instead of the global one, but
that would go against the procedural style of chrome.* APIs
(chrome.devtools.* do; some are unhappy about this).
On the other hand, if you regard chrome.debugger.* as a drop-in
replacement for the WebSocket interface, this is probably ok, as one
would face very similar problems while using a socket. It's a
low-level API anyway, mastering the protocol is going to bring
additional challenges for many anyway.
In the long term, if we have an OO-style SDK to use as an abstraction
of the protocol, it would be perfectly natural to address the problem
there.
Best regards,
Andrey.
In the meantime a couple of small changes to the doc pages would help:
1. on http://code.google.com/chrome/extensions/trunk/experimental.debugger.html
Notes:
"Debugger API serves as an alternate transport for Chrome's remote
debugging protocol. Use debugger to attach to a tab, instrument its
network interaction, debug JavaScript, mutate page's DOM and CSS, etc.
"
could be:
Debugger API serves as an alternate transport for Chrome's remote
debugging protocol. Use chrome.debugger to attach to one or more tabs
to instrument network interaction, debug JavaScript, mutate the DOM
and CSS, etc.
Use the Debuggee tabId to target tabs with sendCommand and route
events by tabId from onEvent callbacks.
2. http://code.google.com/chrome/extensions/trunk/experimental.debugger.html#method-attach
"callback
( optional function )
If an error occurs while attaching to the target, the callback
will be called with no arguments and chrome.extension.lastError will
be set to the error message."
could be (assuming that the callback is called always??)
"callback
( optional function )
Called once the attach operation succeeds or fails. No arguments
are passed to the callback. If the attach fails,
chrome.extension.lastError will be set to the error message"
HTH,
jjb
> I can't find this 'only' bit you are referring to. After all,
> asynchronous error handler suggests that you should not proceed with
> the interaction unless your attach succeeded.
? You're confusing me here. If it was not documented how did I read it
in the documentation and decide to write code to detect it?
But it does not matter, I removed the debuggerWasEnabled approach last week.
>
> tl;dr: You should not assume that the debugger has been enabled unless
> Debugger.enable callback is invoked.
This would be a great line to add to the documentation for enable(). I
know it seems obvious now, but with async APIs the caller generally
wants to issue as many parallel requests as possible.
>
> In your case, chrome.tabs.update operates on the browser level and
> nukes the entire renderer process. We don't have a chance to propagate
> the new renderer state to the browser so that we could restore it post
> navigation.
A 'nice to have' would be a categorization of operations that can
proceed in parallel with debugger requests, including "no operations
what so ever".
jjb