chromium-bidi 0.1.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/README.md +184 -32
  2. package/lib/cjs/bidiMapper/BidiServer.d.ts +36 -0
  3. package/lib/cjs/bidiMapper/BidiServer.js +74 -0
  4. package/lib/cjs/bidiMapper/BidiServer.js.map +1 -0
  5. package/lib/cjs/bidiMapper/BidiTransport.d.ts +22 -0
  6. package/lib/cjs/bidiMapper/BidiTransport.js +19 -0
  7. package/lib/cjs/bidiMapper/BidiTransport.js.map +1 -0
  8. package/lib/cjs/bidiMapper/CdpConnection.d.ts +32 -0
  9. package/lib/cjs/bidiMapper/CdpConnection.js +19 -0
  10. package/lib/cjs/bidiMapper/CdpConnection.js.map +1 -0
  11. package/lib/cjs/bidiMapper/CommandProcessor.d.ts +43 -0
  12. package/lib/cjs/bidiMapper/CommandProcessor.js +136 -0
  13. package/lib/cjs/bidiMapper/CommandProcessor.js.map +1 -0
  14. package/lib/cjs/bidiMapper/OutgoindBidiMessage.d.ts +25 -0
  15. package/lib/cjs/bidiMapper/OutgoindBidiMessage.js +42 -0
  16. package/lib/cjs/bidiMapper/OutgoindBidiMessage.js.map +1 -0
  17. package/lib/cjs/bidiMapper/bidiMapper.d.ts +25 -0
  18. package/lib/cjs/bidiMapper/bidiMapper.js +24 -0
  19. package/lib/cjs/bidiMapper/bidiMapper.js.map +1 -0
  20. package/lib/cjs/bidiMapper/domains/context/browsingContextImpl.d.ts +40 -0
  21. package/lib/cjs/bidiMapper/domains/context/browsingContextImpl.js +365 -0
  22. package/lib/cjs/bidiMapper/domains/context/browsingContextImpl.js.map +1 -0
  23. package/lib/cjs/bidiMapper/domains/context/browsingContextProcessor.d.ts +45 -0
  24. package/lib/cjs/bidiMapper/domains/context/browsingContextProcessor.js +228 -0
  25. package/lib/cjs/bidiMapper/domains/context/browsingContextProcessor.js.map +1 -0
  26. package/lib/cjs/bidiMapper/domains/context/browsingContextStorage.d.ts +26 -0
  27. package/lib/cjs/bidiMapper/domains/context/browsingContextStorage.js +50 -0
  28. package/lib/cjs/bidiMapper/domains/context/browsingContextStorage.js.map +1 -0
  29. package/lib/cjs/bidiMapper/domains/events/EventManager.d.ts +32 -0
  30. package/lib/cjs/bidiMapper/domains/events/EventManager.js +166 -0
  31. package/lib/cjs/bidiMapper/domains/events/EventManager.js.map +1 -0
  32. package/lib/cjs/bidiMapper/domains/events/SubscriptionManager.d.ts +23 -0
  33. package/lib/cjs/bidiMapper/domains/events/SubscriptionManager.js +90 -0
  34. package/lib/cjs/bidiMapper/domains/events/SubscriptionManager.js.map +1 -0
  35. package/lib/cjs/bidiMapper/domains/events/SubscriptionManager.spec.d.ts +16 -0
  36. package/lib/cjs/bidiMapper/domains/events/SubscriptionManager.spec.js +149 -0
  37. package/lib/cjs/bidiMapper/domains/events/SubscriptionManager.spec.js.map +1 -0
  38. package/lib/cjs/bidiMapper/domains/log/logHelper.d.ts +23 -0
  39. package/lib/cjs/bidiMapper/domains/log/logHelper.js +178 -0
  40. package/lib/cjs/bidiMapper/domains/log/logHelper.js.map +1 -0
  41. package/lib/cjs/bidiMapper/domains/log/logHelper_getRemoteValuesText.spec.d.ts +17 -0
  42. package/lib/cjs/bidiMapper/domains/log/logHelper_getRemoteValuesText.spec.js +65 -0
  43. package/lib/cjs/bidiMapper/domains/log/logHelper_getRemoteValuesText.spec.js.map +1 -0
  44. package/lib/cjs/bidiMapper/domains/log/logHelper_logMessageFormatter.spec.d.ts +17 -0
  45. package/lib/cjs/bidiMapper/domains/log/logHelper_logMessageFormatter.spec.js +378 -0
  46. package/lib/cjs/bidiMapper/domains/log/logHelper_logMessageFormatter.spec.js.map +1 -0
  47. package/lib/cjs/bidiMapper/domains/log/logManager.d.ts +23 -0
  48. package/lib/cjs/bidiMapper/domains/log/logManager.js +138 -0
  49. package/lib/cjs/bidiMapper/domains/log/logManager.js.map +1 -0
  50. package/lib/cjs/bidiMapper/domains/script/realm.d.ts +78 -0
  51. package/lib/cjs/bidiMapper/domains/script/realm.js +164 -0
  52. package/lib/cjs/bidiMapper/domains/script/realm.js.map +1 -0
  53. package/lib/cjs/bidiMapper/domains/script/scriptEvaluator.d.ts +42 -0
  54. package/lib/cjs/bidiMapper/domains/script/scriptEvaluator.js +378 -0
  55. package/lib/cjs/bidiMapper/domains/script/scriptEvaluator.js.map +1 -0
  56. package/lib/cjs/bidiMapper/tsconfig.tsbuildinfo +1 -0
  57. package/lib/cjs/bidiServer/bidiServerRunner.d.ts +29 -0
  58. package/{src/.build → lib/cjs}/bidiServer/bidiServerRunner.js +42 -20
  59. package/lib/cjs/bidiServer/bidiServerRunner.js.map +1 -0
  60. package/lib/cjs/bidiServer/index.d.ts +17 -0
  61. package/{src/.build → lib/cjs}/bidiServer/index.js +29 -14
  62. package/lib/cjs/bidiServer/index.js.map +1 -0
  63. package/lib/cjs/bidiServer/mapperReader.d.ts +17 -0
  64. package/{src/.build → lib/cjs}/bidiServer/mapperReader.js +1 -1
  65. package/lib/cjs/bidiServer/mapperReader.js.map +1 -0
  66. package/lib/cjs/bidiServer/mapperServer.d.ts +32 -0
  67. package/{src/.build → lib/cjs}/bidiServer/mapperServer.js +17 -15
  68. package/lib/cjs/bidiServer/mapperServer.js.map +1 -0
  69. package/lib/cjs/bidiServer/tsconfig.tsbuildinfo +1 -0
  70. package/lib/cjs/bidiTab/bidiTab.d.ts +30 -0
  71. package/lib/cjs/bidiTab/bidiTab.js +248 -0
  72. package/lib/cjs/bidiTab/bidiTab.js.map +1 -0
  73. package/lib/cjs/bidiTab/mapperTabPage.d.ts +27 -0
  74. package/lib/cjs/bidiTab/mapperTabPage.js +60 -0
  75. package/lib/cjs/bidiTab/mapperTabPage.js.map +1 -0
  76. package/lib/cjs/bidiTab/tsconfig.tsbuildinfo +1 -0
  77. package/lib/cjs/cdp/cdpClient.d.ts +41 -0
  78. package/lib/cjs/cdp/cdpClient.js +50 -0
  79. package/lib/cjs/cdp/cdpClient.js.map +1 -0
  80. package/lib/cjs/cdp/cdpClient.spec.d.ts +17 -0
  81. package/{src/.build/bidiServer → lib/cjs}/cdp/cdpClient.spec.js +22 -22
  82. package/lib/cjs/cdp/cdpClient.spec.js.map +1 -0
  83. package/lib/cjs/cdp/cdpConnection.d.ts +42 -0
  84. package/{src/.build/bidiServer → lib/cjs}/cdp/cdpConnection.js +30 -31
  85. package/lib/cjs/cdp/cdpConnection.js.map +1 -0
  86. package/lib/cjs/cdp/cdpConnection.spec.d.ts +17 -0
  87. package/{src/.build/bidiServer → lib/cjs}/cdp/cdpConnection.spec.js +16 -16
  88. package/lib/cjs/cdp/cdpConnection.spec.js.map +1 -0
  89. package/lib/cjs/cdp/cdpMessage.d.ts +28 -0
  90. package/{src/.build/bidiServer → lib/cjs}/cdp/cdpMessage.js +0 -0
  91. package/lib/cjs/cdp/cdpMessage.js.map +1 -0
  92. package/lib/cjs/cdp/index.d.ts +19 -0
  93. package/{src/.build/bidiServer → lib/cjs}/cdp/index.js +7 -5
  94. package/lib/cjs/cdp/index.js.map +1 -0
  95. package/lib/cjs/cdp/stubTransport.spec.d.ts +28 -0
  96. package/{src/.build/bidiServer/tests → lib/cjs/cdp}/stubTransport.spec.js +0 -0
  97. package/lib/cjs/cdp/stubTransport.spec.js.map +1 -0
  98. package/lib/cjs/cdp/tsconfig.tsbuildinfo +1 -0
  99. package/lib/cjs/cdp/websocketTransport.d.ts +26 -0
  100. package/{src/.build/bidiServer → lib/cjs}/cdp/websocketTransport.js +0 -0
  101. package/lib/cjs/cdp/websocketTransport.js.map +1 -0
  102. package/lib/cjs/protocol/protocol.d.ts +508 -0
  103. package/lib/cjs/protocol/protocol.js +92 -0
  104. package/lib/cjs/protocol/protocol.js.map +1 -0
  105. package/lib/cjs/protocol/tsconfig.tsbuildinfo +1 -0
  106. package/lib/cjs/protocol-parser/protocol-parser.d.ts +728 -0
  107. package/lib/cjs/protocol-parser/protocol-parser.js +377 -0
  108. package/lib/cjs/protocol-parser/protocol-parser.js.map +1 -0
  109. package/lib/cjs/protocol-parser/tsconfig.tsbuildinfo +1 -0
  110. package/lib/cjs/utils/EventEmitter.d.ts +51 -0
  111. package/lib/cjs/utils/EventEmitter.js +59 -0
  112. package/lib/cjs/utils/EventEmitter.js.map +1 -0
  113. package/lib/cjs/utils/EventEmitter.spec.d.ts +16 -0
  114. package/lib/cjs/utils/EventEmitter.spec.js +109 -0
  115. package/lib/cjs/utils/EventEmitter.spec.js.map +1 -0
  116. package/lib/cjs/utils/buffer.d.ts +29 -0
  117. package/lib/cjs/utils/buffer.js +49 -0
  118. package/lib/cjs/utils/buffer.js.map +1 -0
  119. package/lib/cjs/utils/buffer.spec.d.ts +17 -0
  120. package/lib/cjs/utils/buffer.spec.js +68 -0
  121. package/lib/cjs/utils/buffer.spec.js.map +1 -0
  122. package/lib/cjs/utils/deferred.d.ts +27 -0
  123. package/lib/cjs/utils/deferred.js +54 -0
  124. package/lib/cjs/utils/deferred.js.map +1 -0
  125. package/lib/cjs/utils/idWrapper.d.ts +24 -0
  126. package/lib/cjs/utils/idWrapper.js +34 -0
  127. package/lib/cjs/utils/idWrapper.js.map +1 -0
  128. package/lib/cjs/utils/idWrapper.spec.d.ts +17 -0
  129. package/lib/cjs/utils/idWrapper.spec.js +53 -0
  130. package/lib/cjs/utils/idWrapper.spec.js.map +1 -0
  131. package/lib/cjs/utils/log.d.ts +24 -0
  132. package/lib/cjs/utils/log.js +39 -0
  133. package/lib/cjs/utils/log.js.map +1 -0
  134. package/lib/cjs/utils/processingQueue.d.ts +5 -0
  135. package/lib/cjs/utils/processingQueue.js +59 -0
  136. package/lib/cjs/utils/processingQueue.js.map +1 -0
  137. package/lib/cjs/utils/processingQueue.spec.d.ts +17 -0
  138. package/lib/cjs/utils/processingQueue.spec.js +104 -0
  139. package/lib/cjs/utils/processingQueue.spec.js.map +1 -0
  140. package/lib/cjs/utils/transport.d.ts +25 -0
  141. package/{src/.build/bidiServer → lib/cjs}/utils/transport.js +0 -0
  142. package/lib/cjs/utils/transport.js.map +1 -0
  143. package/lib/cjs/utils/tsconfig.tsbuildinfo +1 -0
  144. package/lib/iife/mapperTab.js +21 -0
  145. package/lib/iife/mapperTab.js.map +1 -0
  146. package/package.json +63 -44
  147. package/src/.build/bidiMapper/mapper.js +0 -26071
  148. package/src/.build/bidiMapper/mapper.js.map +0 -1
  149. package/src/.build/bidiServer/bidiServerRunner.js.map +0 -1
  150. package/src/.build/bidiServer/cdp/cdpClient.js +0 -122
  151. package/src/.build/bidiServer/cdp/cdpClient.js.map +0 -1
  152. package/src/.build/bidiServer/cdp/cdpClient.spec.js.map +0 -1
  153. package/src/.build/bidiServer/cdp/cdpConnection.js.map +0 -1
  154. package/src/.build/bidiServer/cdp/cdpConnection.spec.js.map +0 -1
  155. package/src/.build/bidiServer/cdp/cdpMessage.js.map +0 -1
  156. package/src/.build/bidiServer/cdp/index.js.map +0 -1
  157. package/src/.build/bidiServer/cdp/websocketTransport.js.map +0 -1
  158. package/src/.build/bidiServer/index.js.map +0 -1
  159. package/src/.build/bidiServer/mapperReader.js.map +0 -1
  160. package/src/.build/bidiServer/mapperServer.js.map +0 -1
  161. package/src/.build/bidiServer/tests/stubTransport.spec.js.map +0 -1
  162. package/src/.build/bidiServer/utils/log.js +0 -44
  163. package/src/.build/bidiServer/utils/log.js.map +0 -1
  164. package/src/.build/bidiServer/utils/transport.js.map +0 -1
  165. package/src/index.ts +0 -110
package/README.md CHANGED
@@ -1,13 +1,129 @@
1
1
  # WebDriver BiDi for Chromium [![chromium-bidi on npm](https://img.shields.io/npm/v/chromium-bidi)](https://www.npmjs.com/package/chromium-bidi)
2
2
 
3
+ ![E2E Tests](https://github.com/GoogleChromeLabs/chromium-bidi/actions/workflows/e2e.js.yml/badge.svg)
4
+ ![Unit Tests](https://github.com/GoogleChromeLabs/chromium-bidi/actions/workflows/unit.js.yml/badge.svg)
5
+ ![WPT Tests](https://github.com/GoogleChromeLabs/chromium-bidi/actions/workflows/wpt.yml/badge.svg)
6
+
3
7
  This is an implementation of the
4
- [WebDriver BiDi](https://w3c.github.io/webdriver-bidi/) protocol for Chromium,
5
- implemented as a JavaScript layer translating between BiDi and CDP, running
6
- inside a Chrome tab.
8
+ [WebDriver BiDi](https://w3c.github.io/webdriver-bidi/) protocol with some
9
+ extensions (**BiDi+**)
10
+ for Chromium, implemented as a JavaScript layer translating between BiDi and CDP,
11
+ running inside a Chrome tab.
7
12
 
8
- Current status can be checked here:
9
- [Chromium BiDi progress](https://docs.google.com/spreadsheets/d/1acM-kHlubpwnW1mFboS9hePawq3u1kf21oQzD16q-Ao/edit?usp=sharing&resourcekey=0-PuLHQYLmDJUOXH_mFO-QiA)
10
- .
13
+ Current status can be checked
14
+ in [WPT WebDriver BiDi status](https://wpt.fyi/results/webdriver/tests/bidi).
15
+
16
+ ## BiDi+
17
+
18
+ **"BiDi+"** is an extension of the WebDriver BiDi protocol. In addition to
19
+ the [WebDriver BiDi](https://w3c.github.io/webdriver-bidi/) it has:
20
+
21
+ ### Command `cdp.sendCommand`
22
+
23
+ ```cddl
24
+ CdpSendCommandCommand = {
25
+ method: "cdp.sendCommand",
26
+ params: ScriptEvaluateParameters,
27
+ }
28
+
29
+ CdpSendCommandParameters = {
30
+ cdpMethod: text,
31
+ cdpParams: any,
32
+ cdpSession?: text,
33
+ }
34
+
35
+ CdpSendCommandResult = {
36
+ result: any,
37
+ cdpSession: text,
38
+ }
39
+ ```
40
+
41
+ The command runs the
42
+ described [CDP command](https://chromedevtools.github.io/devtools-protocol)
43
+ and returns result.
44
+
45
+ ### Command `cdp.getSession`
46
+
47
+ ```cddl
48
+ CdpGetSessionCommand = {
49
+ method: "cdp.sendCommand",
50
+ params: ScriptEvaluateParameters,
51
+ }
52
+
53
+ CdpGetSessionParameters = {
54
+ context: BrowsingContext,
55
+ }
56
+
57
+ CdpGetSessionResult = {
58
+ cdpSession: text,
59
+ }
60
+ ```
61
+
62
+ The command returns the default CDP session for the selected browsing context.
63
+
64
+ ### Event `cdp.eventReceived`
65
+
66
+ ```cddl
67
+ CdpEventReceivedEvent = {
68
+ method: "cdp.eventReceived",
69
+ params: ScriptEvaluateParameters,
70
+ }
71
+
72
+ CdpEventReceivedParameters = {
73
+ cdpMethod: text,
74
+ cdpParams: any,
75
+ cdpSession: string,
76
+ }
77
+ ```
78
+
79
+ The event contains a CDP event.
80
+
81
+ ## Field `channel`
82
+
83
+ Each command can be extended with a `channel`:
84
+
85
+ ```cddl
86
+ Command = {
87
+ id: js-uint,
88
+ channel?: text,
89
+ CommandData,
90
+ Extensible,
91
+ }
92
+ ```
93
+
94
+ If provided and non-empty string, the very same `channel` is added to the response:
95
+
96
+ ```cddl
97
+ CommandResponse = {
98
+ id: js-uint,
99
+ channel?: text,
100
+ result: ResultData,
101
+ Extensible,
102
+ }
103
+
104
+ ErrorResponse = {
105
+ id: js-uint / null,
106
+ channel?: text,
107
+ error: ErrorCode,
108
+ message: text,
109
+ ?stacktrace: text,
110
+ Extensible
111
+ }
112
+ ```
113
+
114
+ When client uses
115
+ commands [`session.subscribe`](https://w3c.github.io/webdriver-bidi/#command-session-subscribe)
116
+ and [`session.unsubscribe`](https://w3c.github.io/webdriver-bidi/#command-session-unsubscribe)
117
+ with `channel`, the subscriptions are handled per channel, and the corresponding
118
+ `channel` filed is added to the event message:
119
+
120
+ ```cddl
121
+ Event = {
122
+ channel?: text,
123
+ EventData,
124
+ Extensible,
125
+ }
126
+ ```
11
127
 
12
128
  # Setup
13
129
 
@@ -19,12 +135,13 @@ npm install
19
135
 
20
136
  # Starting the Server
21
137
 
138
+ This will run the server on port `8080`:
139
+
22
140
  ```sh
23
141
  npm run server
24
142
  ```
25
143
 
26
- This will run the server on port 8080. Use the `PORT` environment variable
27
- or `--port=...` argument to run it on another port:
144
+ Use the `PORT=` environment variable or `--port=` argument to run it on another port:
28
145
 
29
146
  ```sh
30
147
  PORT=8081 npm run server
@@ -43,6 +160,17 @@ Use the CLI argument `--headless=false` to run browser in headful mode:
43
160
  npm run server -- --headless=false
44
161
  ```
45
162
 
163
+ Use the `CHANNEL=...` environment variable or `--channel=...` argument with one of
164
+ the following values to run the specific Chrome channel: `chrome`,
165
+ `chrome-beta`, `chrome-canary`, `chrome-dev`.
166
+
167
+ The requested Chrome version should be installed.
168
+
169
+ ```sh
170
+ CHANNEL=chrome-dev npm run server
171
+ npm run server -- --channel=chrome-dev
172
+ ```
173
+
46
174
  ## Starting on Linux and Mac
47
175
 
48
176
  TODO: verify if it works on Windows.
@@ -66,8 +194,8 @@ npm run unit
66
194
 
67
195
  ## e2e tests
68
196
 
69
- The e2e tests are written using Python, in order to learn how to eventually do
70
- this in web-platform-tests.
197
+ The e2e tests are written using Python, in order to learn how to eventually do this
198
+ in web-platform-tests.
71
199
 
72
200
  ### Installation
73
201
 
@@ -79,8 +207,8 @@ python3 -m pip install --user -r tests/requirements.txt
79
207
 
80
208
  ### Running
81
209
 
82
- The e2e tests require BiDi server running on the same host. By default, tests
83
- try to connect to the port `8080`. The server can be run from the project root:
210
+ The e2e tests require BiDi server running on the same host. By default, tests try to
211
+ connect to the port `8080`. The server can be run from the project root:
84
212
 
85
213
  ```sh
86
214
  npm run e2e
@@ -94,15 +222,15 @@ PORT=8081 npm run e2e
94
222
 
95
223
  ## Examples
96
224
 
97
- The examples are stored in the `/examples` folder and are intended to show who
98
- the BiDi protocol can be used. Examples are based on
225
+ The examples are stored in the `/examples` folder and are intended to show who the
226
+ BiDi protocol can be used. Examples are based on
99
227
  [Puppeteer's examples](https://github.com/puppeteer/puppeteer/tree/main/examples)
100
228
  .
101
229
 
102
- ### Instalation
230
+ ### Installation
103
231
 
104
- The examples are written using Python, to align with e2e test. Python 3.6+ and
105
- some dependencies are required:
232
+ The examples are written using Python, to align with e2e test. Python 3.6+ and some
233
+ dependencies are required:
106
234
 
107
235
  ```sh
108
236
  python3 -m pip install --user -r tests/requirements.txt
@@ -110,8 +238,8 @@ python3 -m pip install --user -r tests/requirements.txt
110
238
 
111
239
  ### Running
112
240
 
113
- The examples require BiDi server running on the same host on the port `8080`.
114
- The server can be run from the project root:
241
+ The examples require BiDi server running on the same host on the port `8080`. The
242
+ server can be run from the project root:
115
243
 
116
244
  ```sh
117
245
  npm run server
@@ -120,22 +248,22 @@ npm run server
120
248
  After running server, examples can be simply run:
121
249
 
122
250
  ```sh
123
- python3 examples/cross-browser.py
251
+ python3 examples/console_log_example.py
252
+ python3 examples/script_example.py
124
253
  ```
125
254
 
126
255
  ## WPT
127
256
 
128
257
  WPT is added as
129
- a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules). To get
130
- run WPT tests:
258
+ a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules). To get run
259
+ WPT tests:
131
260
 
132
261
  ### Check out WPT and setup
133
262
 
134
263
  #### 1. Check out WPT
135
264
 
136
265
  ```sh
137
- git submodule init
138
- git submodule update
266
+ git submodule update --init
139
267
  ```
140
268
 
141
269
  #### 2. Go to the WPT folder
@@ -170,8 +298,8 @@ This must be run in a PowerShell session with Administrator privileges:
170
298
  python wpt make-hosts-file | Out-File $env:SystemRoot\System32\drivers\etc\hosts -Encoding ascii -Append
171
299
  ```
172
300
 
173
- If you are behind a proxy, you also need to make sure the domains above are
174
- excluded from your proxy lookups.
301
+ If you are behind a proxy, you also need to make sure the domains above are excluded
302
+ from your proxy lookups.
175
303
 
176
304
  #### 5. Set the `WPT_BROWSER_PATH` environment variable to a Chrome, Edge or Chromium binary to launch. For example, on macOS:
177
305
 
@@ -183,6 +311,10 @@ export WPT_BROWSER_PATH="/Applications/Chromium.app/Contents/MacOS/Chromium"
183
311
 
184
312
  ### Run WPT tests
185
313
 
314
+ #### 1. Make sure you have Chrome Dev instaled
315
+
316
+ https://www.google.com/chrome/dev/
317
+
186
318
  #### 1. Build ChromeDriver BiDi
187
319
 
188
320
  ```sh
@@ -234,12 +366,32 @@ The architecture is described in the
234
366
 
235
367
  There are 2 main modules:
236
368
 
237
- 1. backend WS server in `src`. It runs webSocket server, and for each ws
238
- connection runs an instance of browser with BiDi Mapper.
239
- 2. front-end BiDi Mapper in `src/bidiMapper`. Gets BiDi commands from the
240
- backend, and map them to CDP commands.
369
+ 1. backend WS server in `src`. It runs webSocket server, and for each ws connection
370
+ runs an instance of browser with BiDi Mapper.
371
+ 2. front-end BiDi Mapper in `src/bidiMapper`. Gets BiDi commands from the backend,
372
+ and map them to CDP commands.
241
373
 
242
374
  ## Contributing
243
375
 
244
- The BiDi commands are processed in the `src/bidiMapper/commandProcessor.ts`. To
245
- add a new command, add it to `_processCommand`, write and call processor for it.
376
+ The BiDi commands are processed in the `src/bidiMapper/commandProcessor.ts`. To add a
377
+ new command, add it to `_processCommand`, write and call processor for it.
378
+
379
+ ## Publish new `npm` release
380
+
381
+ 1. On the `main` branch, bump the chromium-bidi version number in `package.json`:
382
+
383
+ ```sh
384
+ npm version patch -m 'Release v%s'
385
+ ```
386
+
387
+ Instead of `patch`, use `minor` or `major` [as needed](https://semver.org/).
388
+
389
+ Note that this produces a Git commit + tag.
390
+
391
+ 1. Push the release commit and tag:
392
+
393
+ ```sh
394
+ git push && git push --tags
395
+ ```
396
+
397
+ Our CI then automatically publishes the new release to npm.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright 2021 Google LLC.
3
+ * Copyright (c) Microsoft Corporation.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { EventEmitter } from '../utils/EventEmitter.js';
18
+ import { BidiTransport } from './BidiTransport.js';
19
+ import type { Message } from '../protocol/protocol.js';
20
+ import { OutgoingBidiMessage } from './OutgoindBidiMessage.js';
21
+ import { BidiParser } from './CommandProcessor.js';
22
+ import { CdpConnection } from './CdpConnection.js';
23
+ declare type BidiServerEvents = {
24
+ message: Message.RawCommandRequest;
25
+ };
26
+ export declare class BidiServer extends EventEmitter<BidiServerEvents> {
27
+ #private;
28
+ private constructor();
29
+ static createAndStart(bidiTransport: BidiTransport, cdpConnection: CdpConnection, selfTargetId: string, parser?: BidiParser): Promise<BidiServer>;
30
+ /**
31
+ * Sends BiDi message.
32
+ */
33
+ emitOutgoingMessage(messageEntry: Promise<OutgoingBidiMessage>): void;
34
+ close(): void;
35
+ }
36
+ export {};
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2021 Google LLC.
4
+ * Copyright (c) Microsoft Corporation.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.BidiServer = void 0;
20
+ const EventEmitter_js_1 = require("../utils/EventEmitter.js");
21
+ const processingQueue_js_1 = require("../utils/processingQueue.js");
22
+ const EventManager_js_1 = require("./domains/events/EventManager.js");
23
+ const CommandProcessor_js_1 = require("./CommandProcessor.js");
24
+ const browsingContextStorage_js_1 = require("./domains/context/browsingContextStorage.js");
25
+ class BidiServer extends EventEmitter_js_1.EventEmitter {
26
+ #messageQueue;
27
+ #transport;
28
+ #commandProcessor;
29
+ constructor(bidiTransport, cdpConnection, selfTargetId, parser) {
30
+ super();
31
+ this.#messageQueue = new processingQueue_js_1.ProcessingQueue(this.#processOutgoingMessage);
32
+ this.#transport = bidiTransport;
33
+ this.#transport.setOnMessage(this.#handleIncomingMessage);
34
+ this.#commandProcessor = new CommandProcessor_js_1.CommandProcessor(cdpConnection, new EventManager_js_1.EventManager(this), selfTargetId, parser);
35
+ this.#commandProcessor.on('response', (response) => {
36
+ this.emitOutgoingMessage(response);
37
+ });
38
+ }
39
+ static async createAndStart(bidiTransport, cdpConnection, selfTargetId, parser) {
40
+ const server = new BidiServer(bidiTransport, cdpConnection, selfTargetId, parser);
41
+ const cdpClient = cdpConnection.browserClient();
42
+ // Needed to get events about new targets.
43
+ await cdpClient.sendCommand('Target.setDiscoverTargets', { discover: true });
44
+ // Needed to automatically attach to new targets.
45
+ await cdpClient.sendCommand('Target.setAutoAttach', {
46
+ autoAttach: true,
47
+ waitForDebuggerOnStart: true,
48
+ flatten: true,
49
+ });
50
+ await Promise.all(browsingContextStorage_js_1.BrowsingContextStorage.getTopLevelContexts().map((c) => c.awaitLoaded()));
51
+ return server;
52
+ }
53
+ #processOutgoingMessage = async (messageEntry) => {
54
+ const message = messageEntry.message;
55
+ if (messageEntry.channel !== null) {
56
+ message['channel'] = messageEntry.channel;
57
+ }
58
+ await this.#transport.sendMessage(message);
59
+ };
60
+ /**
61
+ * Sends BiDi message.
62
+ */
63
+ emitOutgoingMessage(messageEntry) {
64
+ this.#messageQueue.add(messageEntry);
65
+ }
66
+ close() {
67
+ this.#transport.close();
68
+ }
69
+ #handleIncomingMessage = async (message) => {
70
+ this.#commandProcessor.processCommand(message);
71
+ };
72
+ }
73
+ exports.BidiServer = BidiServer;
74
+ //# sourceMappingURL=BidiServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BidiServer.js","sourceRoot":"","sources":["../../../src/bidiMapper/BidiServer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,8DAAsD;AAItD,oEAA4D;AAE5D,sEAA8D;AAC9D,+DAAmE;AAEnE,2FAAmF;AAMnF,MAAa,UAAW,SAAQ,8BAA8B;IAC5D,aAAa,CAAuC;IACpD,UAAU,CAAgB;IAC1B,iBAAiB,CAAmB;IAEpC,YACE,aAA4B,EAC5B,aAA4B,EAC5B,YAAoB,EACpB,MAAmB;QAEnB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,aAAa,GAAG,IAAI,oCAAe,CACtC,IAAI,CAAC,uBAAuB,CAC7B,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC;QAChC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAC1D,IAAI,CAAC,iBAAiB,GAAG,IAAI,sCAAgB,CAC3C,aAAa,EACb,IAAI,8BAAY,CAAC,IAAI,CAAC,EACtB,YAAY,EACZ,MAAM,CACP,CAAC;QACF,IAAI,CAAC,iBAAiB,CAAC,EAAE,CACvB,UAAU,EACV,CAAC,QAAsC,EAAE,EAAE;YACzC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC,CACF,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,cAAc,CAChC,aAA4B,EAC5B,aAA4B,EAC5B,YAAoB,EACpB,MAAmB;QAEnB,MAAM,MAAM,GAAG,IAAI,UAAU,CAC3B,aAAa,EACb,aAAa,EACb,YAAY,EACZ,MAAM,CACP,CAAC;QACF,MAAM,SAAS,GAAG,aAAa,CAAC,aAAa,EAAE,CAAC;QAEhD,0CAA0C;QAC1C,MAAM,SAAS,CAAC,WAAW,CAAC,2BAA2B,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC;QAE3E,iDAAiD;QACjD,MAAM,SAAS,CAAC,WAAW,CAAC,sBAAsB,EAAE;YAClD,UAAU,EAAE,IAAI;YAChB,sBAAsB,EAAE,IAAI;YAC5B,OAAO,EAAE,IAAI;SACd,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CACf,kDAAsB,CAAC,mBAAmB,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CACzE,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,uBAAuB,GAAG,KAAK,EAAE,YAAiC,EAAE,EAAE;QACpE,MAAM,OAAO,GAAG,YAAY,CAAC,OAAc,CAAC;QAE5C,IAAI,YAAY,CAAC,OAAO,KAAK,IAAI,EAAE;YACjC,OAAO,CAAC,SAAS,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC;SAC3C;QAED,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEF;;OAEG;IACH,mBAAmB,CAAC,YAA0C;QAC5D,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED,sBAAsB,GAAG,KAAK,EAAE,OAAkC,EAAE,EAAE;QACpE,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC,CAAC;CACH;AArFD,gCAqFC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright 2022 Google LLC.
3
+ * Copyright (c) Microsoft Corporation.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { Message } from '../protocol/protocol.js';
18
+ export interface BidiTransport {
19
+ setOnMessage: (handler: (message: Message.RawCommandRequest) => Promise<void>) => void;
20
+ sendMessage: (message: Message.OutgoingMessage) => Promise<void>;
21
+ close(): void;
22
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2022 Google LLC.
4
+ * Copyright (c) Microsoft Corporation.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ //# sourceMappingURL=BidiTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BidiTransport.js","sourceRoot":"","sources":["../../../src/bidiMapper/BidiTransport.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright 2022 Google LLC.
3
+ * Copyright (c) Microsoft Corporation.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
18
+ import { EventEmitter } from '../utils/EventEmitter.js';
19
+ declare type CdpEvents = {
20
+ [Property in keyof ProtocolMapping.Events]: ProtocolMapping.Events[Property][0];
21
+ };
22
+ /**
23
+ * CDP interfaces that BiDi Mapper expects.
24
+ */
25
+ export interface CdpConnection {
26
+ browserClient(): CdpClient;
27
+ getCdpClient(sessionId: string): CdpClient;
28
+ }
29
+ export interface CdpClient extends EventEmitter<CdpEvents> {
30
+ sendCommand<T extends keyof ProtocolMapping.Commands>(method: T, ...params: ProtocolMapping.Commands[T]['paramsType']): Promise<ProtocolMapping.Commands[T]['returnType']>;
31
+ }
32
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2022 Google LLC.
4
+ * Copyright (c) Microsoft Corporation.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ //# sourceMappingURL=CdpConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CdpConnection.js","sourceRoot":"","sources":["../../../src/bidiMapper/CdpConnection.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright 2021 Google LLC.
3
+ * Copyright (c) Microsoft Corporation.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Message, Session, BrowsingContext, Script, CDP } from '../protocol/protocol.js';
18
+ import { CdpConnection } from './CdpConnection.js';
19
+ import { OutgoingBidiMessage } from './OutgoindBidiMessage.js';
20
+ import { IEventManager } from './domains/events/EventManager.js';
21
+ import { EventEmitter } from '../utils/EventEmitter.js';
22
+ declare type CommandProcessorEvents = {
23
+ response: Promise<OutgoingBidiMessage>;
24
+ };
25
+ export interface BidiParser {
26
+ parseGetRealmsParams(params: object): Script.GetRealmsParameters;
27
+ parseCallFunctionParams(params: object): Script.CallFunctionParameters;
28
+ parseEvaluateParams(params: object): Script.EvaluateParameters;
29
+ parseDisownParams(params: object): Script.DisownParameters;
30
+ parseSendCommandParams(params: object): CDP.SendCommandParams;
31
+ parseGetSessionParams(params: object): CDP.GetSessionParams;
32
+ parseNavigateParams(params: object): BrowsingContext.NavigateParameters;
33
+ parseGetTreeParams(params: object): BrowsingContext.GetTreeParameters;
34
+ parseSubscribeParams(params: object): Session.SubscribeParameters;
35
+ parseCreateParams(params: object): BrowsingContext.CreateParameters;
36
+ parseCloseParams(params: object): BrowsingContext.CloseParameters;
37
+ }
38
+ export declare class CommandProcessor extends EventEmitter<CommandProcessorEvents> {
39
+ #private;
40
+ constructor(cdpConnection: CdpConnection, eventManager: IEventManager, selfTargetId: string, parser?: BidiParser);
41
+ processCommand: (command: Message.RawCommandRequest) => Promise<void>;
42
+ }
43
+ export {};