@ai-ecoverse/sliccy-browser 0.1.35 → 0.1.37
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/package.json +1 -1
- package/src/browser.js +15 -10
package/package.json
CHANGED
package/src/browser.js
CHANGED
|
@@ -304,12 +304,15 @@ async function findTabNow(query = {}) {
|
|
|
304
304
|
throw new Error('browser.findTab: query requires `domain` or `urlMatch`');
|
|
305
305
|
}
|
|
306
306
|
const tabs = await listTabs();
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
307
|
+
const wanted = domain?.toLowerCase();
|
|
308
|
+
const re = urlMatch === undefined ? undefined : compilePattern(urlMatch, 'browser.findTab');
|
|
309
|
+
return (
|
|
310
|
+
tabs.find(
|
|
311
|
+
(tab) =>
|
|
312
|
+
(wanted === undefined || hostnameOf(tab.url)?.toLowerCase() === wanted) &&
|
|
313
|
+
(re === undefined || re.test(tab.url))
|
|
314
|
+
) ?? null
|
|
315
|
+
);
|
|
313
316
|
}
|
|
314
317
|
|
|
315
318
|
export async function ensureTab(url, options) {
|
|
@@ -359,11 +362,11 @@ function evalSourceAsync(tab, source) {
|
|
|
359
362
|
|
|
360
363
|
export { evalSource as eval, evalSourceAsync as evalAsync };
|
|
361
364
|
|
|
362
|
-
function evaluate(tab, source, awaitPromise) {
|
|
363
|
-
return using(() => evaluateNow(tab, source, awaitPromise));
|
|
365
|
+
function evaluate(tab, source, awaitPromise, decodeJson = true) {
|
|
366
|
+
return using(() => evaluateNow(tab, source, awaitPromise, decodeJson));
|
|
364
367
|
}
|
|
365
368
|
|
|
366
|
-
async function evaluateNow(tab, source, awaitPromise) {
|
|
369
|
+
async function evaluateNow(tab, source, awaitPromise, decodeJson) {
|
|
367
370
|
const { client, sessionId } = await sessionFor(targetIdOf(tab));
|
|
368
371
|
const result = await client.send(
|
|
369
372
|
'Runtime.evaluate',
|
|
@@ -377,7 +380,8 @@ async function evaluateNow(tab, source, awaitPromise) {
|
|
|
377
380
|
if (result?.exceptionDetails) {
|
|
378
381
|
throw new Error(exceptionMessage(result.exceptionDetails));
|
|
379
382
|
}
|
|
380
|
-
|
|
383
|
+
const value = result?.result?.value;
|
|
384
|
+
return decodeJson ? unwrapEvalResult(value) : value;
|
|
381
385
|
}
|
|
382
386
|
|
|
383
387
|
export async function cookie(tab, name) {
|
|
@@ -398,6 +402,7 @@ export async function localStorage(tab, key) {
|
|
|
398
402
|
const raw = await evaluate(
|
|
399
403
|
tab,
|
|
400
404
|
`(function(){try{var v=window.localStorage.getItem(${JSON.stringify(key)});return v===null?null:String(v);}catch(e){return null;}})()`,
|
|
405
|
+
false,
|
|
401
406
|
false
|
|
402
407
|
);
|
|
403
408
|
if (raw === null || raw === undefined) return null;
|