Skip to content

Commit 4524926

Browse files
author
SentienceDEV
committed
fix tests
1 parent 73b0b84 commit 4524926

File tree

3 files changed

+83
-6
lines changed

3 files changed

+83
-6
lines changed

sentience/extension/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import init, { analyze_page_with_options, analyze_page, prune_for_api } from "../pkg/sentience_core.js";
1+
import init, { analyze_page_with_options, analyze_page, prune_for_api } from "./pkg/sentience_core.js";
22

33
let wasmReady = !1, wasmInitPromise = null;
44

sentience/extension/injected_api.js

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,9 @@
792792
}
793793
});
794794
} catch (error) {}
795-
const processed = await function(rawData, options) {
795+
let processed = null;
796+
try {
797+
processed = await function(rawData, options) {
796798
return new Promise((resolve, reject) => {
797799
const requestId = Math.random().toString(36).substring(7);
798800
let resolved = !1;
@@ -823,7 +825,82 @@
823825
}
824826
});
825827
}(allRawElements, options);
826-
if (!processed || !processed.elements) throw new Error("WASM processing returned invalid result");
828+
} catch (error) {
829+
processed = {
830+
elements: (allRawElements || []).map(r => {
831+
const rect = r && r.rect || {
832+
x: 0,
833+
y: 0,
834+
width: 0,
835+
height: 0
836+
}, attrs = r && r.attributes || {}, role = attrs.role || r && (r.inferred_role || r.inferredRole) || ("a" === r.tag ? "link" : "generic");
837+
return {
838+
id: Number(r && r.id || 0),
839+
role: String(role || "generic"),
840+
text: r && (r.text || r.semantic_text || r.semanticText) || null,
841+
importance: 1,
842+
bbox: {
843+
x: Number(rect.x || 0),
844+
y: Number(rect.y || 0),
845+
width: Number(rect.width || 0),
846+
height: Number(rect.height || 0)
847+
},
848+
visual_cues: {
849+
is_primary: !1,
850+
is_clickable: !1
851+
},
852+
in_viewport: !0,
853+
is_occluded: !!(r && (r.occluded || r.is_occluded)),
854+
z_index: 0,
855+
name: attrs.aria_label || attrs.ariaLabel || null,
856+
value: r && r.value || null,
857+
input_type: attrs.type_ || attrs.type || null,
858+
checked: "boolean" == typeof r.checked ? r.checked : null,
859+
disabled: "boolean" == typeof r.disabled ? r.disabled : null,
860+
expanded: "boolean" == typeof r.expanded ? r.expanded : null
861+
};
862+
}),
863+
raw_elements: allRawElements,
864+
duration: null
865+
};
866+
}
867+
if (!processed || !processed.elements) processed = {
868+
elements: (allRawElements || []).map(r => {
869+
const rect = r && r.rect || {
870+
x: 0,
871+
y: 0,
872+
width: 0,
873+
height: 0
874+
}, attrs = r && r.attributes || {}, role = attrs.role || r && (r.inferred_role || r.inferredRole) || ("a" === r.tag ? "link" : "generic");
875+
return {
876+
id: Number(r && r.id || 0),
877+
role: String(role || "generic"),
878+
text: r && (r.text || r.semantic_text || r.semanticText) || null,
879+
importance: 1,
880+
bbox: {
881+
x: Number(rect.x || 0),
882+
y: Number(rect.y || 0),
883+
width: Number(rect.width || 0),
884+
height: Number(rect.height || 0)
885+
},
886+
visual_cues: {
887+
is_primary: !1,
888+
is_clickable: !1
889+
},
890+
in_viewport: !0,
891+
is_occluded: !!(r && (r.occluded || r.is_occluded)),
892+
z_index: 0,
893+
name: attrs.aria_label || attrs.ariaLabel || null,
894+
value: r && r.value || null,
895+
input_type: attrs.type_ || attrs.type || null,
896+
checked: "boolean" == typeof r.checked ? r.checked : null,
897+
disabled: "boolean" == typeof r.disabled ? r.disabled : null,
898+
expanded: "boolean" == typeof r.expanded ? r.expanded : null
899+
};
900+
}),
901+
raw_elements: allRawElements,
902+
duration: null
903+
};
827904
let screenshot = null;
828905
options.screenshot && (screenshot = await function(options) {
829906
return new Promise(resolve => {

sentience/extension/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"permissions": ["activeTab", "scripting"],
77
"host_permissions": ["<all_urls>"],
88
"background": {
9-
"service_worker": "dist/background.js",
9+
"service_worker": "background.js",
1010
"type": "module"
1111
},
1212
"web_accessible_resources": [
@@ -18,13 +18,13 @@
1818
"content_scripts": [
1919
{
2020
"matches": ["<all_urls>"],
21-
"js": ["dist/content.js"],
21+
"js": ["content.js"],
2222
"run_at": "document_start",
2323
"all_frames": true
2424
},
2525
{
2626
"matches": ["<all_urls>"],
27-
"js": ["dist/injected_api.js"],
27+
"js": ["injected_api.js"],
2828
"run_at": "document_idle",
2929
"world": "MAIN",
3030
"all_frames": true

0 commit comments

Comments
 (0)