Skip to content

Commit

Permalink
Use the hardcoded protocol version by default
Browse files Browse the repository at this point in the history
Fetching it from the remote repo introduces a non-negligible latency every time
a connection with Chrome is established and it is kind of breaking change since
this operation was almost immediate before. Those who desire to use this feature
will have to explicitly request it.

Related to #10
  • Loading branch information
cyrus-and committed Oct 7, 2015
1 parent 258c7c2 commit 9d903e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ Remote Debugging Protocol versions

Currently it is not possible to fetch the protocol descriptor
([`protocol.json`][local-json]) directly from the instrumented Chrome instance
(see [#10][issue]); rather, that file is fetched from the proper source
repository at every connection, and if that is not possible, the [harcoded
version](local-json) is used. This file is fetched from time to time from the
[Blink repo][remote-json] and pushed to this repository.
(see [#10][issue]); rather, that file can be fetched from the proper [source
repository][remote-json] at every connection. By default, the [hardcoded local
version][local-json] is used.

To override the above behavior there are basically three options:

1. update the local copy with `make update-protocol`;

2. pass a custom protocol descriptor upon
2. pass a custom protocol descriptor (use `null` to fetch it from the remote
repository) upon
[connection](https://github.com/cyrus-and/chrome-remote-interface#moduleoptions-callback);

3. use the *raw* version of the [commands](#chromesendmethod-params-callback)
Expand All @@ -129,9 +129,11 @@ Protocol][rdb].
array returned by `http://host:port/json` containing the tab list and must
return the numeric index of a tab. Defaults to a function which returns the
currently active tab (`function (tabs) { return 0; }`).
- `protocol`: [Remote Debugging Protocol][rdb] descriptor object.
Defaults to the protocol fetched directly from the Chrome repository, if
available, otherwise falls back to an hardcoded version.
- `protocol`: [Remote Debugging Protocol][rdb] descriptor object. Passing `null`
causes the proper protocol descriptor to be fetched from the remote Chrome
repository according to the version exposed by the instrumented Chrome
instance, falling back to the default if that is not possible. Defaults to the
[hardcoded local version][local-json].

`callback` is a listener automatically added to the `connect` event of the
returned `EventEmitter`.
Expand Down
10 changes: 8 additions & 2 deletions lib/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ function connectToChrome() {
}
});
};
// try fetching the protocol from Chrome unless not specified
if (typeof self.protocol === 'undefined') {
// fetch the protocol
if (self.protocol === null) {
// try fetching the protocol from Chrome falling back to the hardcoded
// version otherwise
Chrome.Protocol(options, function (err, fromChrome, protocol) {
if (err) {
self.notifier.emit('error', err);
Expand All @@ -313,6 +315,10 @@ function connectToChrome() {
}
});
} else {
// use the one provided falling back to the hardcoded version otherwise
if (typeof self.protocol === 'undefined') {
self.protocol = require('./protocol.json');
}
continueConnection();
}
}
Expand Down

0 comments on commit 9d903e0

Please sign in to comment.