surfsky 0.0.2 → 0.0.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.
- package/README.md +4 -0
- package/dist/index.js +21 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -282,6 +282,10 @@ waits for one of its own and throws `RateLimitError` only if it has none.
|
|
|
282
282
|
|
|
283
283
|
### Reading
|
|
284
284
|
|
|
285
|
+
`selector` is CSS, or XPath when it starts with `//`, `..` or `xpath=`. XPath
|
|
286
|
+
covers the DOM reads below and `screenshot({ selector })`; `innerText`,
|
|
287
|
+
`allInnerTexts`, `selectOption` and the input methods take CSS only.
|
|
288
|
+
|
|
285
289
|
| Method | Description |
|
|
286
290
|
| ------------------------------------------------------------ | --------------------------------------------------------------------------------------- |
|
|
287
291
|
| `url()`, `title()` | Current URL and title. |
|
package/dist/index.js
CHANGED
|
@@ -865,6 +865,9 @@ const WORLD_NAME = "utility";
|
|
|
865
865
|
/** A dialog is answered after this long, as a person would. */
|
|
866
866
|
const DIALOG_DELAY = [600, 1400];
|
|
867
867
|
const FUNCTION = /^\s*(async\s+)?(function\b|\([^()]*\)\s*=>|[\w$]+\s*=>)/;
|
|
868
|
+
function asXPath(s) {
|
|
869
|
+
return /^\s*(xpath=|\/\/|\.\.)/.test(s) ? s.trim().replace(/^xpath=/, "") : void 0;
|
|
870
|
+
}
|
|
868
871
|
const SELECT = `(selector, value, label) => {
|
|
869
872
|
const el = document.querySelector(selector);
|
|
870
873
|
if (!el) return null;
|
|
@@ -1329,6 +1332,8 @@ var Page = class extends Actions {
|
|
|
1329
1332
|
}
|
|
1330
1333
|
async count(selector) {
|
|
1331
1334
|
const document = await this.send("DOM.getDocument", { depth: 0 });
|
|
1335
|
+
const xpath = asXPath(selector);
|
|
1336
|
+
if (xpath !== void 0) return (await this.#search(xpath)).length;
|
|
1332
1337
|
return ((await this.send("DOM.querySelectorAll", {
|
|
1333
1338
|
nodeId: document.root.nodeId,
|
|
1334
1339
|
selector
|
|
@@ -1371,11 +1376,26 @@ var Page = class extends Actions {
|
|
|
1371
1376
|
}
|
|
1372
1377
|
async #nodeId(selector) {
|
|
1373
1378
|
const document = await this.send("DOM.getDocument", { depth: 0 });
|
|
1379
|
+
const xpath = asXPath(selector);
|
|
1380
|
+
if (xpath !== void 0) return (await this.#search(xpath))[0];
|
|
1374
1381
|
return (await this.send("DOM.querySelector", {
|
|
1375
1382
|
nodeId: document.root.nodeId,
|
|
1376
1383
|
selector
|
|
1377
1384
|
})).nodeId || void 0;
|
|
1378
1385
|
}
|
|
1386
|
+
async #search(query) {
|
|
1387
|
+
const { searchId, resultCount = 0 } = await this.send("DOM.performSearch", { query });
|
|
1388
|
+
try {
|
|
1389
|
+
if (!resultCount) return [];
|
|
1390
|
+
return (await this.send("DOM.getSearchResults", {
|
|
1391
|
+
searchId,
|
|
1392
|
+
fromIndex: 0,
|
|
1393
|
+
toIndex: resultCount
|
|
1394
|
+
})).nodeIds ?? [];
|
|
1395
|
+
} finally {
|
|
1396
|
+
await this.send("DOM.discardSearchResults", { searchId }).catch(() => void 0);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1379
1399
|
/** Wait until the URL contains the fragment. Returns the URL. */
|
|
1380
1400
|
async waitForUrl(fragment, options = {}) {
|
|
1381
1401
|
const deadline = new Deadline(options.timeout ?? 3e4, `the page did not reach '${fragment}'`);
|
|
@@ -2598,7 +2618,7 @@ var Proxies = class {
|
|
|
2598
2618
|
};
|
|
2599
2619
|
//#endregion
|
|
2600
2620
|
//#region src/version.ts
|
|
2601
|
-
const VERSION = "0.0.
|
|
2621
|
+
const VERSION = "0.0.3";
|
|
2602
2622
|
//#endregion
|
|
2603
2623
|
//#region src/client.ts
|
|
2604
2624
|
function userAgent() {
|