@browserbasehq/sdk 1.5.0 → 2.0.0-alpha.1

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 (268) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +198 -4
  3. package/README.md +266 -76
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +13 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +88 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +77 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +240 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +903 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +871 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +53 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +143 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +127 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +132 -0
  87. package/index.d.ts +132 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +115 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +87 -0
  92. package/index.mjs.map +1 -0
  93. package/package.json +93 -31
  94. package/resource.d.ts +6 -0
  95. package/resource.d.ts.map +1 -0
  96. package/resource.js +11 -0
  97. package/resource.js.map +1 -0
  98. package/resource.mjs +7 -0
  99. package/resource.mjs.map +1 -0
  100. package/resources/contexts.d.ts +82 -0
  101. package/resources/contexts.d.ts.map +1 -0
  102. package/resources/contexts.js +29 -0
  103. package/resources/contexts.js.map +1 -0
  104. package/resources/contexts.mjs +25 -0
  105. package/resources/contexts.mjs.map +1 -0
  106. package/resources/extensions.d.ts +35 -0
  107. package/resources/extensions.d.ts.map +1 -0
  108. package/resources/extensions.js +56 -0
  109. package/resources/extensions.js.map +1 -0
  110. package/resources/extensions.mjs +29 -0
  111. package/resources/extensions.mjs.map +1 -0
  112. package/resources/index.d.ts +5 -0
  113. package/resources/index.d.ts.map +1 -0
  114. package/resources/index.js +13 -0
  115. package/resources/index.js.map +1 -0
  116. package/resources/index.mjs +6 -0
  117. package/resources/index.mjs.map +1 -0
  118. package/resources/projects.d.ts +36 -0
  119. package/resources/projects.d.ts.map +1 -0
  120. package/resources/projects.js +29 -0
  121. package/resources/projects.js.map +1 -0
  122. package/resources/projects.mjs +25 -0
  123. package/resources/projects.mjs.map +1 -0
  124. package/resources/sessions/downloads.d.ts +10 -0
  125. package/resources/sessions/downloads.d.ts.map +1 -0
  126. package/resources/sessions/downloads.js +15 -0
  127. package/resources/sessions/downloads.js.map +1 -0
  128. package/resources/sessions/downloads.mjs +11 -0
  129. package/resources/sessions/downloads.mjs.map +1 -0
  130. package/resources/sessions/index.d.ts +6 -0
  131. package/resources/sessions/index.d.ts.map +1 -0
  132. package/resources/sessions/index.js +15 -0
  133. package/resources/sessions/index.js.map +1 -0
  134. package/resources/sessions/index.mjs +7 -0
  135. package/resources/sessions/index.mjs.map +1 -0
  136. package/resources/sessions/logs.d.ts +47 -0
  137. package/resources/sessions/logs.d.ts.map +1 -0
  138. package/resources/sessions/logs.js +17 -0
  139. package/resources/sessions/logs.js.map +1 -0
  140. package/resources/sessions/logs.mjs +13 -0
  141. package/resources/sessions/logs.mjs.map +1 -0
  142. package/resources/sessions/recording.d.ts +29 -0
  143. package/resources/sessions/recording.d.ts.map +1 -0
  144. package/resources/sessions/recording.js +17 -0
  145. package/resources/sessions/recording.js.map +1 -0
  146. package/resources/sessions/recording.mjs +13 -0
  147. package/resources/sessions/recording.mjs.map +1 -0
  148. package/resources/sessions/sessions.d.ts +338 -0
  149. package/resources/sessions/sessions.d.ts.map +1 -0
  150. package/resources/sessions/sessions.js +80 -0
  151. package/resources/sessions/sessions.js.map +1 -0
  152. package/resources/sessions/sessions.mjs +53 -0
  153. package/resources/sessions/sessions.mjs.map +1 -0
  154. package/resources/sessions/uploads.d.ts +20 -0
  155. package/resources/sessions/uploads.d.ts.map +1 -0
  156. package/resources/sessions/uploads.js +41 -0
  157. package/resources/sessions/uploads.js.map +1 -0
  158. package/resources/sessions/uploads.mjs +14 -0
  159. package/resources/sessions/uploads.mjs.map +1 -0
  160. package/shims/node.d.ts +26 -0
  161. package/shims/node.d.ts.map +1 -0
  162. package/shims/node.js +6 -0
  163. package/shims/node.js.map +1 -0
  164. package/shims/node.mjs +4 -0
  165. package/shims/node.mjs.map +1 -0
  166. package/shims/web.d.ts +26 -0
  167. package/shims/web.d.ts.map +1 -0
  168. package/shims/web.js +6 -0
  169. package/shims/web.js.map +1 -0
  170. package/shims/web.mjs +4 -0
  171. package/shims/web.mjs.map +1 -0
  172. package/src/_shims/MultipartBody.ts +9 -0
  173. package/src/_shims/README.md +46 -0
  174. package/src/_shims/auto/runtime-bun.ts +4 -0
  175. package/src/_shims/auto/runtime-node.ts +4 -0
  176. package/src/_shims/auto/runtime.ts +4 -0
  177. package/src/_shims/auto/types-node.ts +4 -0
  178. package/src/_shims/auto/types.d.ts +101 -0
  179. package/src/_shims/auto/types.js +3 -0
  180. package/src/_shims/auto/types.mjs +3 -0
  181. package/src/_shims/bun-runtime.ts +14 -0
  182. package/src/_shims/index.d.ts +81 -0
  183. package/src/_shims/index.js +13 -0
  184. package/src/_shims/index.mjs +7 -0
  185. package/src/_shims/manual-types.d.ts +12 -0
  186. package/src/_shims/manual-types.js +3 -0
  187. package/src/_shims/manual-types.mjs +3 -0
  188. package/src/_shims/node-runtime.ts +81 -0
  189. package/src/_shims/node-types.d.ts +42 -0
  190. package/src/_shims/node-types.js +3 -0
  191. package/src/_shims/node-types.mjs +3 -0
  192. package/src/_shims/registry.ts +67 -0
  193. package/src/_shims/web-runtime.ts +103 -0
  194. package/src/_shims/web-types.d.ts +83 -0
  195. package/src/_shims/web-types.js +3 -0
  196. package/src/_shims/web-types.mjs +3 -0
  197. package/src/core.ts +1197 -0
  198. package/src/error.ts +146 -0
  199. package/src/index.ts +210 -0
  200. package/src/lib/.keep +4 -0
  201. package/src/resource.ts +11 -0
  202. package/src/resources/contexts.ts +108 -0
  203. package/src/resources/extensions.ts +55 -0
  204. package/src/resources/index.ts +21 -0
  205. package/src/resources/projects.ts +56 -0
  206. package/src/resources/sessions/downloads.ts +14 -0
  207. package/src/resources/sessions/index.ts +16 -0
  208. package/src/resources/sessions/logs.ts +68 -0
  209. package/src/resources/sessions/recording.ts +40 -0
  210. package/src/resources/sessions/sessions.ts +451 -0
  211. package/src/resources/sessions/uploads.ts +34 -0
  212. package/src/shims/node.ts +50 -0
  213. package/src/shims/web.ts +50 -0
  214. package/src/tsconfig.json +11 -0
  215. package/src/uploads.ts +256 -0
  216. package/src/version.ts +1 -0
  217. package/uploads.d.ts +75 -0
  218. package/uploads.d.ts.map +1 -0
  219. package/uploads.js +170 -0
  220. package/uploads.js.map +1 -0
  221. package/uploads.mjs +157 -0
  222. package/uploads.mjs.map +1 -0
  223. package/version.d.ts +2 -0
  224. package/version.d.ts.map +1 -0
  225. package/version.js +5 -0
  226. package/version.js.map +1 -0
  227. package/version.mjs +2 -0
  228. package/version.mjs.map +1 -0
  229. package/dist/index.d.ts +0 -138
  230. package/dist/index.js +0 -228
  231. package/dist/integrations/ai-sdk.d.ts +0 -18
  232. package/dist/integrations/ai-sdk.js +0 -19
  233. package/dist/recorder/call-metadata.d.ts +0 -66
  234. package/dist/recorder/call-metadata.js +0 -2
  235. package/dist/recorder/crypto.d.ts +0 -1
  236. package/dist/recorder/crypto.js +0 -10
  237. package/dist/recorder/css-utils.d.ts +0 -2
  238. package/dist/recorder/css-utils.js +0 -34
  239. package/dist/recorder/generator.d.ts +0 -31
  240. package/dist/recorder/generator.js +0 -154
  241. package/dist/recorder/javascript-generator.d.ts +0 -29
  242. package/dist/recorder/javascript-generator.js +0 -256
  243. package/dist/recorder/language.d.ts +0 -127
  244. package/dist/recorder/language.js +0 -21
  245. package/dist/recorder/recorder-types.d.ts +0 -108
  246. package/dist/recorder/recorder-types.js +0 -2
  247. package/dist/recorder/recorder.d.ts +0 -35
  248. package/dist/recorder/recorder.js +0 -333
  249. package/dist/recorder/time.d.ts +0 -1
  250. package/dist/recorder/time.js +0 -42
  251. package/dist/recorder/timeout-runner.d.ts +0 -6
  252. package/dist/recorder/timeout-runner.js +0 -19
  253. package/dist/recorder/utils/isomorphic/css-parser.d.ts +0 -41
  254. package/dist/recorder/utils/isomorphic/css-parser.js +0 -291
  255. package/dist/recorder/utils/isomorphic/css-tokenizer.d.ts +0 -171
  256. package/dist/recorder/utils/isomorphic/css-tokenizer.js +0 -986
  257. package/dist/recorder/utils/isomorphic/locator-generators.d.ts +0 -79
  258. package/dist/recorder/utils/isomorphic/locator-generators.js +0 -666
  259. package/dist/recorder/utils/isomorphic/locator-parser.d.ts +0 -17
  260. package/dist/recorder/utils/isomorphic/locator-parser.js +0 -244
  261. package/dist/recorder/utils/isomorphic/locator-utils.d.ts +0 -43
  262. package/dist/recorder/utils/isomorphic/locator-utils.js +0 -69
  263. package/dist/recorder/utils/isomorphic/selector-parser.d.ts +0 -48
  264. package/dist/recorder/utils/isomorphic/selector-parser.js +0 -483
  265. package/dist/recorder/utils/isomorphic/string-utils.d.ts +0 -28
  266. package/dist/recorder/utils/isomorphic/string-utils.js +0 -123
  267. package/dist/recorder/utils.d.ts +0 -20
  268. package/dist/recorder/utils.js +0 -32
@@ -1,483 +0,0 @@
1
- "use strict";
2
- /**
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.customCSSNames = exports.isInvalidSelectorError = exports.InvalidSelectorError = void 0;
19
- exports.parseSelector = parseSelector;
20
- exports.splitSelectorByFrame = splitSelectorByFrame;
21
- exports.stringifySelector = stringifySelector;
22
- exports.visitAllSelectorParts = visitAllSelectorParts;
23
- exports.parseAttributeSelector = parseAttributeSelector;
24
- const css_parser_1 = require("./css-parser");
25
- var css_parser_2 = require("./css-parser");
26
- Object.defineProperty(exports, "InvalidSelectorError", { enumerable: true, get: function () { return css_parser_2.InvalidSelectorError; } });
27
- Object.defineProperty(exports, "isInvalidSelectorError", { enumerable: true, get: function () { return css_parser_2.isInvalidSelectorError; } });
28
- const kNestedSelectorNames = new Set([
29
- 'internal:has',
30
- 'internal:has-not',
31
- 'internal:and',
32
- 'internal:or',
33
- 'internal:chain',
34
- 'left-of',
35
- 'right-of',
36
- 'above',
37
- 'below',
38
- 'near',
39
- ]);
40
- const kNestedSelectorNamesWithDistance = new Set([
41
- 'left-of',
42
- 'right-of',
43
- 'above',
44
- 'below',
45
- 'near',
46
- ]);
47
- exports.customCSSNames = new Set([
48
- 'not',
49
- 'is',
50
- 'where',
51
- 'has',
52
- 'scope',
53
- 'light',
54
- 'visible',
55
- 'text',
56
- 'text-matches',
57
- 'text-is',
58
- 'has-text',
59
- 'above',
60
- 'below',
61
- 'right-of',
62
- 'left-of',
63
- 'near',
64
- 'nth-match',
65
- ]);
66
- function parseSelector(selector) {
67
- const parsedStrings = parseSelectorString(selector);
68
- const parts = [];
69
- for (const part of parsedStrings.parts) {
70
- if (part.name === 'css' || part.name === 'css:light') {
71
- if (part.name === 'css:light')
72
- part.body = ':light(' + part.body + ')';
73
- const parsedCSS = (0, css_parser_1.parseCSS)(part.body, exports.customCSSNames);
74
- parts.push({
75
- name: 'css',
76
- body: parsedCSS.selector,
77
- source: part.body,
78
- });
79
- continue;
80
- }
81
- if (kNestedSelectorNames.has(part.name)) {
82
- let innerSelector;
83
- let distance;
84
- try {
85
- const unescaped = JSON.parse('[' + part.body + ']');
86
- if (!Array.isArray(unescaped) ||
87
- unescaped.length < 1 ||
88
- unescaped.length > 2 ||
89
- typeof unescaped[0] !== 'string')
90
- throw new css_parser_1.InvalidSelectorError(`Malformed selector: ${part.name}=` + part.body);
91
- innerSelector = unescaped[0];
92
- if (unescaped.length === 2) {
93
- if (typeof unescaped[1] !== 'number' ||
94
- !kNestedSelectorNamesWithDistance.has(part.name))
95
- throw new css_parser_1.InvalidSelectorError(`Malformed selector: ${part.name}=` + part.body);
96
- distance = unescaped[1];
97
- }
98
- }
99
- catch (e) {
100
- throw new css_parser_1.InvalidSelectorError(`Malformed selector: ${part.name}=` + part.body);
101
- }
102
- const nested = {
103
- name: part.name,
104
- source: part.body,
105
- body: { parsed: parseSelector(innerSelector), distance },
106
- };
107
- const lastFrame = [...nested.body.parsed.parts]
108
- .reverse()
109
- .find((part) => part.name === 'internal:control' && part.body === 'enter-frame');
110
- const lastFrameIndex = lastFrame
111
- ? nested.body.parsed.parts.indexOf(lastFrame)
112
- : -1;
113
- // Allow nested selectors to start with the same frame selector.
114
- if (lastFrameIndex !== -1 &&
115
- selectorPartsEqual(nested.body.parsed.parts.slice(0, lastFrameIndex + 1), parts.slice(0, lastFrameIndex + 1)))
116
- nested.body.parsed.parts.splice(0, lastFrameIndex + 1);
117
- parts.push(nested);
118
- continue;
119
- }
120
- parts.push({ ...part, source: part.body });
121
- }
122
- if (kNestedSelectorNames.has(parts[0].name))
123
- throw new css_parser_1.InvalidSelectorError(`"${parts[0].name}" selector cannot be first`);
124
- return {
125
- capture: parsedStrings.capture,
126
- parts,
127
- };
128
- }
129
- function splitSelectorByFrame(selectorText) {
130
- const selector = parseSelector(selectorText);
131
- const result = [];
132
- let chunk = {
133
- parts: [],
134
- };
135
- let chunkStartIndex = 0;
136
- for (let i = 0; i < selector.parts.length; ++i) {
137
- const part = selector.parts[i];
138
- if (part.name === 'internal:control' && part.body === 'enter-frame') {
139
- if (!chunk.parts.length)
140
- throw new css_parser_1.InvalidSelectorError('Selector cannot start with entering frame, select the iframe first');
141
- result.push(chunk);
142
- chunk = { parts: [] };
143
- chunkStartIndex = i + 1;
144
- continue;
145
- }
146
- if (selector.capture === i)
147
- chunk.capture = i - chunkStartIndex;
148
- chunk.parts.push(part);
149
- }
150
- if (!chunk.parts.length)
151
- throw new css_parser_1.InvalidSelectorError(`Selector cannot end with entering frame, while parsing selector ${selectorText}`);
152
- result.push(chunk);
153
- if (typeof selector.capture === 'number' &&
154
- typeof result[result.length - 1].capture !== 'number')
155
- throw new css_parser_1.InvalidSelectorError(`Can not capture the selector before diving into the frame. Only use * after the last frame has been selected`);
156
- return result;
157
- }
158
- function selectorPartsEqual(list1, list2) {
159
- return (stringifySelector({ parts: list1 }) === stringifySelector({ parts: list2 }));
160
- }
161
- function stringifySelector(selector, forceEngineName) {
162
- if (typeof selector === 'string')
163
- return selector;
164
- return selector.parts
165
- .map((p, i) => {
166
- let includeEngine = true;
167
- if (!forceEngineName && i !== selector.capture) {
168
- if (p.name === 'css')
169
- includeEngine = false;
170
- else if ((p.name === 'xpath' && p.source.startsWith('//')) ||
171
- p.source.startsWith('..'))
172
- includeEngine = false;
173
- }
174
- const prefix = includeEngine ? p.name + '=' : '';
175
- return `${i === selector.capture ? '*' : ''}${prefix}${p.source}`;
176
- })
177
- .join(' >> ');
178
- }
179
- function visitAllSelectorParts(selector, visitor) {
180
- const visit = (selector, nested) => {
181
- for (const part of selector.parts) {
182
- visitor(part, nested);
183
- if (kNestedSelectorNames.has(part.name))
184
- visit(part.body.parsed, true);
185
- }
186
- };
187
- visit(selector, false);
188
- }
189
- function parseSelectorString(selector) {
190
- let index = 0;
191
- let quote;
192
- let start = 0;
193
- const result = { parts: [] };
194
- const append = () => {
195
- const part = selector.substring(start, index).trim();
196
- const eqIndex = part.indexOf('=');
197
- let name;
198
- let body;
199
- if (eqIndex !== -1 &&
200
- part
201
- .substring(0, eqIndex)
202
- .trim()
203
- .match(/^[a-zA-Z_0-9-+:*]+$/)) {
204
- name = part.substring(0, eqIndex).trim();
205
- body = part.substring(eqIndex + 1);
206
- }
207
- else if (part.length > 1 &&
208
- part[0] === '"' &&
209
- part[part.length - 1] === '"') {
210
- name = 'text';
211
- body = part;
212
- }
213
- else if (part.length > 1 &&
214
- part[0] === "'" &&
215
- part[part.length - 1] === "'") {
216
- name = 'text';
217
- body = part;
218
- }
219
- else if (/^\(*\/\//.test(part) || part.startsWith('..')) {
220
- // If selector starts with '//' or '//' prefixed with multiple opening
221
- // parenthesis, consider xpath. @see https://github.com/microsoft/playwright/issues/817
222
- // If selector starts with '..', consider xpath as well.
223
- name = 'xpath';
224
- body = part;
225
- }
226
- else {
227
- name = 'css';
228
- body = part;
229
- }
230
- let capture = false;
231
- if (name[0] === '*') {
232
- capture = true;
233
- name = name.substring(1);
234
- }
235
- result.parts.push({ name, body });
236
- if (capture) {
237
- if (result.capture !== undefined)
238
- throw new css_parser_1.InvalidSelectorError(`Only one of the selectors can capture using * modifier`);
239
- result.capture = result.parts.length - 1;
240
- }
241
- };
242
- if (!selector.includes('>>')) {
243
- index = selector.length;
244
- append();
245
- return result;
246
- }
247
- const shouldIgnoreTextSelectorQuote = () => {
248
- const prefix = selector.substring(start, index);
249
- const match = prefix.match(/^\s*text\s*=(.*)$/);
250
- // Must be a text selector with some text before the quote.
251
- return !!match && !!match[1];
252
- };
253
- while (index < selector.length) {
254
- const c = selector[index];
255
- if (c === '\\' && index + 1 < selector.length) {
256
- index += 2;
257
- }
258
- else if (c === quote) {
259
- quote = undefined;
260
- index++;
261
- }
262
- else if (!quote &&
263
- (c === '"' || c === "'" || c === '`') &&
264
- !shouldIgnoreTextSelectorQuote()) {
265
- quote = c;
266
- index++;
267
- }
268
- else if (!quote && c === '>' && selector[index + 1] === '>') {
269
- append();
270
- index += 2;
271
- start = index;
272
- }
273
- else {
274
- index++;
275
- }
276
- }
277
- append();
278
- return result;
279
- }
280
- function parseAttributeSelector(selector, allowUnquotedStrings) {
281
- let wp = 0;
282
- let EOL = selector.length === 0;
283
- const next = () => selector[wp] || '';
284
- const eat1 = () => {
285
- const result = next();
286
- ++wp;
287
- EOL = wp >= selector.length;
288
- return result;
289
- };
290
- const syntaxError = (stage) => {
291
- if (EOL)
292
- throw new css_parser_1.InvalidSelectorError(`Unexpected end of selector while parsing selector \`${selector}\``);
293
- throw new css_parser_1.InvalidSelectorError(`Error while parsing selector \`${selector}\` - unexpected symbol "${next()}" at position ${wp}` +
294
- (stage ? ' during ' + stage : ''));
295
- };
296
- function skipSpaces() {
297
- while (!EOL && /\s/.test(next()))
298
- eat1();
299
- }
300
- function isCSSNameChar(char) {
301
- // https://www.w3.org/TR/css-syntax-3/#ident-token-diagram
302
- return (char >= '\u0080' || // non-ascii
303
- (char >= '\u0030' && char <= '\u0039') || // digit
304
- (char >= '\u0041' && char <= '\u005a') || // uppercase letter
305
- (char >= '\u0061' && char <= '\u007a') || // lowercase letter
306
- (char >= '\u0030' && char <= '\u0039') || // digit
307
- char === '\u005f' || // "_"
308
- char === '\u002d'); // "-"
309
- }
310
- function readIdentifier() {
311
- let result = '';
312
- skipSpaces();
313
- while (!EOL && isCSSNameChar(next()))
314
- result += eat1();
315
- return result;
316
- }
317
- function readQuotedString(quote) {
318
- let result = eat1();
319
- if (result !== quote)
320
- syntaxError('parsing quoted string');
321
- while (!EOL && next() !== quote) {
322
- if (next() === '\\')
323
- eat1();
324
- result += eat1();
325
- }
326
- if (next() !== quote)
327
- syntaxError('parsing quoted string');
328
- result += eat1();
329
- return result;
330
- }
331
- function readRegularExpression() {
332
- if (eat1() !== '/')
333
- syntaxError('parsing regular expression');
334
- let source = '';
335
- let inClass = false;
336
- // https://262.ecma-international.org/11.0/#sec-literals-regular-expression-literals
337
- while (!EOL) {
338
- if (next() === '\\') {
339
- source += eat1();
340
- if (EOL)
341
- syntaxError('parsing regular expression');
342
- }
343
- else if (inClass && next() === ']') {
344
- inClass = false;
345
- }
346
- else if (!inClass && next() === '[') {
347
- inClass = true;
348
- }
349
- else if (!inClass && next() === '/') {
350
- break;
351
- }
352
- source += eat1();
353
- }
354
- if (eat1() !== '/')
355
- syntaxError('parsing regular expression');
356
- let flags = '';
357
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
358
- while (!EOL && next().match(/[dgimsuy]/))
359
- flags += eat1();
360
- try {
361
- return new RegExp(source, flags);
362
- }
363
- catch (e) {
364
- throw new css_parser_1.InvalidSelectorError(`Error while parsing selector \`${selector}\`: ${e.message}`);
365
- }
366
- }
367
- function readAttributeToken() {
368
- let token = '';
369
- skipSpaces();
370
- if (next() === `'` || next() === `"`)
371
- token = readQuotedString(next()).slice(1, -1);
372
- else
373
- token = readIdentifier();
374
- if (!token)
375
- syntaxError('parsing property path');
376
- return token;
377
- }
378
- function readOperator() {
379
- skipSpaces();
380
- let op = '';
381
- if (!EOL)
382
- op += eat1();
383
- if (!EOL && op !== '=')
384
- op += eat1();
385
- if (!['=', '*=', '^=', '$=', '|=', '~='].includes(op))
386
- syntaxError('parsing operator');
387
- return op;
388
- }
389
- function readAttribute() {
390
- // skip leading [
391
- eat1();
392
- // read attribute name:
393
- // foo.bar
394
- // 'foo' . "ba zz"
395
- const jsonPath = [];
396
- jsonPath.push(readAttributeToken());
397
- skipSpaces();
398
- while (next() === '.') {
399
- eat1();
400
- jsonPath.push(readAttributeToken());
401
- skipSpaces();
402
- }
403
- // check property is truthy: [enabled]
404
- if (next() === ']') {
405
- eat1();
406
- return {
407
- name: jsonPath.join('.'),
408
- jsonPath,
409
- op: '<truthy>',
410
- value: null,
411
- caseSensitive: false,
412
- };
413
- }
414
- const operator = readOperator();
415
- let value = undefined;
416
- let caseSensitive = true;
417
- skipSpaces();
418
- if (next() === '/') {
419
- if (operator !== '=')
420
- throw new css_parser_1.InvalidSelectorError(`Error while parsing selector \`${selector}\` - cannot use ${operator} in attribute with regular expression`);
421
- value = readRegularExpression();
422
- }
423
- else if (next() === `'` || next() === `"`) {
424
- value = readQuotedString(next()).slice(1, -1);
425
- skipSpaces();
426
- if (next() === 'i' || next() === 'I') {
427
- caseSensitive = false;
428
- eat1();
429
- }
430
- else if (next() === 's' || next() === 'S') {
431
- caseSensitive = true;
432
- eat1();
433
- }
434
- }
435
- else {
436
- value = '';
437
- while (!EOL &&
438
- (isCSSNameChar(next()) || next() === '+' || next() === '.'))
439
- value += eat1();
440
- if (value === 'true') {
441
- value = true;
442
- }
443
- else if (value === 'false') {
444
- value = false;
445
- }
446
- else {
447
- if (!allowUnquotedStrings) {
448
- value = +value;
449
- if (Number.isNaN(value))
450
- syntaxError('parsing attribute value');
451
- }
452
- }
453
- }
454
- skipSpaces();
455
- if (next() !== ']')
456
- syntaxError('parsing attribute value');
457
- eat1();
458
- if (operator !== '=' && typeof value !== 'string')
459
- throw new css_parser_1.InvalidSelectorError(`Error while parsing selector \`${selector}\` - cannot use ${operator} in attribute with non-string matching value - ${value}`);
460
- return {
461
- name: jsonPath.join('.'),
462
- jsonPath,
463
- op: operator,
464
- value,
465
- caseSensitive,
466
- };
467
- }
468
- const result = {
469
- name: '',
470
- attributes: [],
471
- };
472
- result.name = readIdentifier();
473
- skipSpaces();
474
- while (next() === '[') {
475
- result.attributes.push(readAttribute());
476
- skipSpaces();
477
- }
478
- if (!EOL)
479
- syntaxError(undefined);
480
- if (!result.name && !result.attributes.length)
481
- throw new css_parser_1.InvalidSelectorError(`Error while parsing selector \`${selector}\` - selector cannot be empty`);
482
- return result;
483
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- export declare function escapeWithQuotes(text: string, char?: string): string;
17
- export declare function isString(obj: any): obj is string;
18
- export declare function toTitleCase(name: string): string;
19
- export declare function toSnakeCase(name: string): string;
20
- export declare function cssEscape(s: string): string;
21
- export declare function quoteCSSAttributeValue(text: string): string;
22
- export declare function normalizeWhiteSpace(text: string): string;
23
- export declare function normalizeEscapedRegexQuotes(source: string): string;
24
- export declare function escapeForTextSelector(text: string | RegExp, exact: boolean): string;
25
- export declare function escapeForAttributeSelector(value: string | RegExp, exact: boolean): string;
26
- export declare function trimString(input: string, cap: number, suffix?: string): string;
27
- export declare function trimStringWithEllipsis(input: string, cap: number): string;
28
- export declare function escapeRegExp(s: string): string;
@@ -1,123 +0,0 @@
1
- "use strict";
2
- /**
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.escapeWithQuotes = escapeWithQuotes;
19
- exports.isString = isString;
20
- exports.toTitleCase = toTitleCase;
21
- exports.toSnakeCase = toSnakeCase;
22
- exports.cssEscape = cssEscape;
23
- exports.quoteCSSAttributeValue = quoteCSSAttributeValue;
24
- exports.normalizeWhiteSpace = normalizeWhiteSpace;
25
- exports.normalizeEscapedRegexQuotes = normalizeEscapedRegexQuotes;
26
- exports.escapeForTextSelector = escapeForTextSelector;
27
- exports.escapeForAttributeSelector = escapeForAttributeSelector;
28
- exports.trimString = trimString;
29
- exports.trimStringWithEllipsis = trimStringWithEllipsis;
30
- exports.escapeRegExp = escapeRegExp;
31
- // NOTE: this function should not be used to escape any selectors.
32
- function escapeWithQuotes(text, char = '\'') {
33
- const stringified = JSON.stringify(text);
34
- const escapedText = stringified.substring(1, stringified.length - 1).replace(/\\"/g, '"');
35
- if (char === '\'')
36
- return char + escapedText.replace(/[']/g, '\\\'') + char;
37
- if (char === '"')
38
- return char + escapedText.replace(/["]/g, '\\"') + char;
39
- if (char === '`')
40
- return char + escapedText.replace(/[`]/g, '`') + char;
41
- throw new Error('Invalid escape char');
42
- }
43
- function isString(obj) {
44
- return typeof obj === 'string' || obj instanceof String;
45
- }
46
- function toTitleCase(name) {
47
- return name.charAt(0).toUpperCase() + name.substring(1);
48
- }
49
- function toSnakeCase(name) {
50
- // E.g. ignoreHTTPSErrors => ignore_https_errors.
51
- return name.replace(/([a-z0-9])([A-Z])/g, '$1_$2').replace(/([A-Z])([A-Z][a-z])/g, '$1_$2').toLowerCase();
52
- }
53
- function cssEscape(s) {
54
- let result = '';
55
- for (let i = 0; i < s.length; i++)
56
- result += cssEscapeOne(s, i);
57
- return result;
58
- }
59
- function quoteCSSAttributeValue(text) {
60
- return `"${cssEscape(text).replace(/\\ /g, ' ')}"`;
61
- }
62
- function cssEscapeOne(s, i) {
63
- // https://drafts.csswg.org/cssom/#serialize-an-identifier
64
- const c = s.charCodeAt(i);
65
- if (c === 0x0000)
66
- return '\uFFFD';
67
- if ((c >= 0x0001 && c <= 0x001f) ||
68
- (c >= 0x0030 && c <= 0x0039 && (i === 0 || (i === 1 && s.charCodeAt(0) === 0x002d))))
69
- return '\\' + c.toString(16) + ' ';
70
- if (i === 0 && c === 0x002d && s.length === 1)
71
- return '\\' + s.charAt(i);
72
- if (c >= 0x0080 || c === 0x002d || c === 0x005f || (c >= 0x0030 && c <= 0x0039) ||
73
- (c >= 0x0041 && c <= 0x005a) || (c >= 0x0061 && c <= 0x007a))
74
- return s.charAt(i);
75
- return '\\' + s.charAt(i);
76
- }
77
- function normalizeWhiteSpace(text) {
78
- return text.replace(/\u200b/g, '').trim().replace(/\s+/g, ' ');
79
- }
80
- function normalizeEscapedRegexQuotes(source) {
81
- // This function reverses the effect of escapeRegexForSelector below.
82
- // Odd number of backslashes followed by the quote -> remove unneeded backslash.
83
- return source.replace(/(^|[^\\])(\\\\)*\\(['"`])/g, '$1$2$3');
84
- }
85
- function escapeRegexForSelector(re) {
86
- // Unicode mode does not allow "identity character escapes", so we do not escape and
87
- // hope that it does not contain quotes and/or >> signs.
88
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape
89
- // TODO: rework RE usages in internal selectors away from literal representation to json, e.g. {source,flags}.
90
- if (re.unicode || re.unicodeSets)
91
- return String(re);
92
- // Even number of backslashes followed by the quote -> insert a backslash.
93
- return String(re).replace(/(^|[^\\])(\\\\)*(["'`])/g, '$1$2\\$3').replace(/>>/g, '\\>\\>');
94
- }
95
- function escapeForTextSelector(text, exact) {
96
- if (typeof text !== 'string')
97
- return escapeRegexForSelector(text);
98
- return `${JSON.stringify(text)}${exact ? 's' : 'i'}`;
99
- }
100
- function escapeForAttributeSelector(value, exact) {
101
- if (typeof value !== 'string')
102
- return escapeRegexForSelector(value);
103
- // TODO: this should actually be
104
- // cssEscape(value).replace(/\\ /g, ' ')
105
- // However, our attribute selectors do not conform to CSS parsing spec,
106
- // so we escape them differently.
107
- return `"${value.replace(/\\/g, '\\\\').replace(/["]/g, '\\"')}"${exact ? 's' : 'i'}`;
108
- }
109
- function trimString(input, cap, suffix = '') {
110
- if (input.length <= cap)
111
- return input;
112
- const chars = [...input];
113
- if (chars.length > cap)
114
- return chars.slice(0, cap - suffix.length).join('') + suffix;
115
- return chars.join('');
116
- }
117
- function trimStringWithEllipsis(input, cap) {
118
- return trimString(input, cap, '\u2026');
119
- }
120
- function escapeRegExp(s) {
121
- // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
122
- return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
123
- }
@@ -1,20 +0,0 @@
1
- import * as actions from './recorder-types';
2
- export type KeyboardModifier = 'Alt' | 'Control' | 'Meta' | 'Shift';
3
- export type SmartKeyboardModifier = KeyboardModifier | 'ControlOrMeta';
4
- export type MouseClickOptions = {
5
- strict?: boolean;
6
- force?: boolean;
7
- noWaitAfter?: boolean;
8
- modifiers?: ('Alt' | 'Control' | 'ControlOrMeta' | 'Meta' | 'Shift')[];
9
- position?: actions.Point;
10
- delay?: number;
11
- button?: 'left' | 'right' | 'middle';
12
- clickCount?: number;
13
- timeout?: number;
14
- trial?: boolean;
15
- };
16
- export declare function toClickOptions(action: actions.ClickAction): {
17
- method: 'click' | 'dblclick';
18
- options: MouseClickOptions;
19
- };
20
- export declare function toModifiers(modifiers: number): SmartKeyboardModifier[];
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toClickOptions = toClickOptions;
4
- exports.toModifiers = toModifiers;
5
- function toClickOptions(action) {
6
- let method = 'click';
7
- if (action.clickCount === 2)
8
- method = 'dblclick';
9
- const modifiers = toModifiers(action.modifiers);
10
- const options = {};
11
- if (action.button !== 'left')
12
- options.button = action.button;
13
- if (modifiers.length)
14
- options.modifiers = modifiers;
15
- if (action.clickCount > 2)
16
- options.clickCount = action.clickCount;
17
- if (action.position)
18
- options.position = action.position;
19
- return { method, options };
20
- }
21
- function toModifiers(modifiers) {
22
- const result = [];
23
- if (modifiers & 1)
24
- result.push('Alt');
25
- if (modifiers & 2)
26
- result.push('ControlOrMeta');
27
- if (modifiers & 4)
28
- result.push('ControlOrMeta');
29
- if (modifiers & 8)
30
- result.push('Shift');
31
- return result;
32
- }