diff --git a/sentience/extension/background.js b/sentience/extension/background.js index bb5ad6f..8537307 100644 --- a/sentience/extension/background.js +++ b/sentience/extension/background.js @@ -1,63 +1 @@ -// background.js - Service Worker for screenshot capture -// Chrome extensions can only capture screenshots from the background script -// Listen for screenshot requests from content script -chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { - if (request.action === 'captureScreenshot') { - handleScreenshotCapture(sender.tab.id, request.options) - .then(screenshot => { - sendResponse({ success: true, screenshot }); - }) - .catch(error => { - console.error('[Sentience] Screenshot capture failed:', error); - sendResponse({ - success: false, - error: error.message || 'Screenshot capture failed' - }); - }); - - // Return true to indicate we'll send response asynchronously - return true; - } -}); - -/** - * Capture screenshot of the active tab - * @param {number} tabId - Tab ID to capture - * @param {Object} options - Screenshot options - * @returns {Promise} Base64-encoded PNG data URL - */ -async function handleScreenshotCapture(tabId, options = {}) { - try { - const { - format = 'png', // 'png' or 'jpeg' - quality = 90 // JPEG quality (0-100), ignored for PNG - } = options; - - // Capture visible tab as data URL - const dataUrl = await chrome.tabs.captureVisibleTab(null, { - format: format, - quality: quality - }); - - console.log(`[Sentience] Screenshot captured: ${format}, size: ${dataUrl.length} bytes`); - - return dataUrl; - } catch (error) { - console.error('[Sentience] Screenshot error:', error); - throw new Error(`Failed to capture screenshot: ${error.message}`); - } -} - -/** - * Optional: Add viewport-specific capture (requires additional setup) - * This would allow capturing specific regions, not just visible area - */ -async function captureRegion(tabId, region) { - // For region capture, you'd need to: - // 1. Capture full visible tab - // 2. Use Canvas API to crop to region - // 3. Return cropped image - - // Not implemented in this basic version - throw new Error('Region capture not yet implemented'); -} +Not Found \ No newline at end of file diff --git a/sentience/extension/content.js b/sentience/extension/content.js index de24fa5..8537307 100644 --- a/sentience/extension/content.js +++ b/sentience/extension/content.js @@ -1,22 +1 @@ -// content.js - ISOLATED WORLD -console.log('[Sentience] Bridge loaded.'); - -// 1. Pass Extension ID to Main World (So WASM knows where to load from) -document.documentElement.dataset.sentienceExtensionId = chrome.runtime.id; - -// 2. Proxy for Screenshots (The only thing Isolated World needs to do) -window.addEventListener('message', (event) => { - // Security check: only accept messages from same window - if (event.source !== window || event.data.type !== 'SENTIENCE_SCREENSHOT_REQUEST') return; - - chrome.runtime.sendMessage( - { action: 'captureScreenshot', options: event.data.options }, - (response) => { - window.postMessage({ - type: 'SENTIENCE_SCREENSHOT_RESULT', - requestId: event.data.requestId, - screenshot: response?.success ? response.screenshot : null - }, '*'); - } - ); -}); \ No newline at end of file +Not Found \ No newline at end of file diff --git a/sentience/extension/injected_api.js b/sentience/extension/injected_api.js index 8f6eb15..8537307 100644 --- a/sentience/extension/injected_api.js +++ b/sentience/extension/injected_api.js @@ -1,438 +1 @@ -// injected_api.js - MAIN WORLD -(async () => { - // 1. Get Extension ID (Wait for content.js to set it) - const getExtensionId = () => document.documentElement.dataset.sentienceExtensionId; - let extId = getExtensionId(); - - // Safety poller for async loading race conditions - if (!extId) { - await new Promise(resolve => { - const check = setInterval(() => { - extId = getExtensionId(); - if (extId) { clearInterval(check); resolve(); } - }, 50); - }); - } - - const EXT_URL = `chrome-extension://${extId}/`; - console.log('[SentienceAPI.com] Initializing from:', EXT_URL); - - window.sentience_registry = []; - let wasmModule = null; - - // --- HELPER: Deep Walker --- - function getAllElements(root = document) { - const elements = []; - const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT); - while(walker.nextNode()) { - const node = walker.currentNode; - elements.push(node); - if (node.shadowRoot) elements.push(...getAllElements(node.shadowRoot)); - } - return elements; - } - - // --- HELPER: Smart Text Extractor --- - function getText(el) { - if (el.getAttribute('aria-label')) return el.getAttribute('aria-label'); - if (el.tagName === 'INPUT') return el.value || el.placeholder || ''; - if (el.tagName === 'IMG') return el.alt || ''; - return (el.innerText || '').replace(/\s+/g, ' ').trim().substring(0, 100); - } - - // --- HELPER: Viewport Check (NEW) --- - function isInViewport(rect) { - return ( - rect.top < window.innerHeight && rect.bottom > 0 && - rect.left < window.innerWidth && rect.right > 0 - ); - } - - // --- HELPER: Occlusion Check (NEW) --- - function isOccluded(el, rect) { - // Fast center-point check - const cx = rect.x + rect.width / 2; - const cy = rect.y + rect.height / 2; - - // If point is off-screen, elementFromPoint returns null, assume NOT occluded for safety - if (cx < 0 || cx > window.innerWidth || cy < 0 || cy > window.innerHeight) return false; - - const topEl = document.elementFromPoint(cx, cy); - if (!topEl) return false; - - // It's visible if the top element is us, or contains us, or we contain it - return !(el === topEl || el.contains(topEl) || topEl.contains(el)); - } - - // --- HELPER: Screenshot Bridge --- - function captureScreenshot(options) { - return new Promise(resolve => { - const requestId = Math.random().toString(36).substring(7); - const listener = (e) => { - if (e.data.type === 'SENTIENCE_SCREENSHOT_RESULT' && e.data.requestId === requestId) { - window.removeEventListener('message', listener); - resolve(e.data.screenshot); - } - }; - window.addEventListener('message', listener); - window.postMessage({ type: 'SENTIENCE_SCREENSHOT_REQUEST', requestId, options }, '*'); - }); - } - - // --- HELPER: Get Raw HTML for Turndown/External Processing --- - // Returns cleaned HTML that can be processed by Turndown or other Node.js libraries - function getRawHTML(root) { - const sourceRoot = root || document.body; - const clone = sourceRoot.cloneNode(true); - - // Remove unwanted elements by tag name (simple and reliable) - const unwantedTags = ['nav', 'footer', 'header', 'script', 'style', 'noscript', 'iframe', 'svg']; - unwantedTags.forEach(tag => { - const elements = clone.querySelectorAll(tag); - elements.forEach(el => { - if (el.parentNode) { - el.parentNode.removeChild(el); - } - }); - }); - - // Remove invisible elements from original DOM and find matching ones in clone - // We'll use a simple approach: mark elements in original, then remove from clone - const invisibleSelectors = []; - const walker = document.createTreeWalker( - sourceRoot, - NodeFilter.SHOW_ELEMENT, - null, - false - ); - - let node; - while (node = walker.nextNode()) { - const tag = node.tagName.toLowerCase(); - if (tag === 'head' || tag === 'title') continue; - - const style = window.getComputedStyle(node); - if (style.display === 'none' || style.visibility === 'hidden' || - (node.offsetWidth === 0 && node.offsetHeight === 0)) { - // Build a selector for this element - let selector = tag; - if (node.id) { - selector = `#${node.id}`; - } else if (node.className && typeof node.className === 'string') { - const classes = node.className.trim().split(/\s+/).filter(c => c); - if (classes.length > 0) { - selector = `${tag}.${classes.join('.')}`; - } - } - invisibleSelectors.push(selector); - } - } - - // Remove invisible elements from clone (if we can find them) - invisibleSelectors.forEach(selector => { - try { - const elements = clone.querySelectorAll(selector); - elements.forEach(el => { - if (el.parentNode) { - el.parentNode.removeChild(el); - } - }); - } catch (e) { - // Invalid selector, skip - } - }); - - // Resolve relative URLs in links and images - const links = clone.querySelectorAll('a[href]'); - links.forEach(link => { - const href = link.getAttribute('href'); - if (href && !href.startsWith('http://') && !href.startsWith('https://') && !href.startsWith('#')) { - try { - link.setAttribute('href', new URL(href, document.baseURI).href); - } catch (e) { - // Keep original href if URL parsing fails - } - } - }); - - const images = clone.querySelectorAll('img[src]'); - images.forEach(img => { - const src = img.getAttribute('src'); - if (src && !src.startsWith('http://') && !src.startsWith('https://') && !src.startsWith('data:')) { - try { - img.setAttribute('src', new URL(src, document.baseURI).href); - } catch (e) { - // Keep original src if URL parsing fails - } - } - }); - - return clone.innerHTML; - } - - // --- HELPER: Simple Markdown Converter (Lightweight) --- - // Uses getRawHTML() and then converts to markdown for consistency - function convertToMarkdown(root) { - // Get cleaned HTML first - const rawHTML = getRawHTML(root); - - // Create a temporary container to parse the HTML - const tempDiv = document.createElement('div'); - tempDiv.innerHTML = rawHTML; - - let markdown = ''; - let insideLink = false; // Track if we're inside an tag - - function walk(node) { - if (node.nodeType === Node.TEXT_NODE) { - // Keep minimal whitespace to prevent words merging - // Strip newlines inside text nodes to prevent broken links - const text = node.textContent.replace(/[\r\n]+/g, ' ').replace(/\s+/g, ' '); - if (text.trim()) markdown += text; - return; - } - - if (node.nodeType !== Node.ELEMENT_NODE) return; - - const tag = node.tagName.toLowerCase(); - - // Prefix - if (tag === 'h1') markdown += '\n# '; - if (tag === 'h2') markdown += '\n## '; - if (tag === 'h3') markdown += '\n### '; - if (tag === 'li') markdown += '\n- '; - // IMPORTANT: Don't add newlines for block elements when inside a link - if (!insideLink && (tag === 'p' || tag === 'div' || tag === 'br')) markdown += '\n'; - if (tag === 'strong' || tag === 'b') markdown += '**'; - if (tag === 'em' || tag === 'i') markdown += '_'; - if (tag === 'a') { - markdown += '['; - insideLink = true; // Mark that we're entering a link - } - - // Children - if (node.shadowRoot) { - Array.from(node.shadowRoot.childNodes).forEach(walk); - } else { - node.childNodes.forEach(walk); - } - - // Suffix - if (tag === 'a') { - // Get absolute URL from href attribute (already resolved in getRawHTML) - const href = node.getAttribute('href'); - if (href) markdown += `](${href})`; - else markdown += ']'; - insideLink = false; // Mark that we're exiting the link - } - if (tag === 'strong' || tag === 'b') markdown += '**'; - if (tag === 'em' || tag === 'i') markdown += '_'; - // IMPORTANT: Don't add newlines for block elements when inside a link (suffix section too) - if (!insideLink && (tag === 'h1' || tag === 'h2' || tag === 'h3' || tag === 'p' || tag === 'div')) markdown += '\n'; - } - - walk(tempDiv); - - // Cleanup: remove excessive newlines - return markdown.replace(/\n{3,}/g, '\n\n').trim(); - } - - // --- HELPER: Raw Text Extractor --- - function convertToText(root) { - let text = ''; - function walk(node) { - if (node.nodeType === Node.TEXT_NODE) { - text += node.textContent; - return; - } - if (node.nodeType === Node.ELEMENT_NODE) { - const tag = node.tagName.toLowerCase(); - // Skip nav/footer/header/script/style/noscript/iframe/svg - if (['nav', 'footer', 'header', 'script', 'style', 'noscript', 'iframe', 'svg'].includes(tag)) return; - - const style = window.getComputedStyle(node); - if (style.display === 'none' || style.visibility === 'hidden') return; - - // Block level elements get a newline - const isBlock = style.display === 'block' || style.display === 'flex' || node.tagName === 'P' || node.tagName === 'DIV'; - if (isBlock) text += ' '; - - if (node.shadowRoot) { - Array.from(node.shadowRoot.childNodes).forEach(walk); - } else { - node.childNodes.forEach(walk); - } - - if (isBlock) text += '\n'; - } - } - walk(root || document.body); - return text.replace(/\n{3,}/g, '\n\n').trim(); - } - - // Load WASM - try { - const wasmUrl = EXT_URL + 'pkg/sentience_core.js'; - const module = await import(wasmUrl); - const imports = { - env: { - js_click_element: (id) => { - const el = window.sentience_registry[id]; - if (el) { el.click(); el.focus(); } - } - } - }; - await module.default(undefined, imports); - wasmModule = module; - - // Verify functions are available - if (!wasmModule.analyze_page) { - console.error('[SentienceAPI.com] WASM functions not available'); - } else { - console.log('[SentienceAPI.com] ✓ API Ready!'); - console.log('[SentienceAPI.com] Available functions:', Object.keys(wasmModule).filter(k => k.startsWith('analyze'))); - } - } catch (e) { - console.error('[SentienceAPI.com] WASM Load Failed:', e); - } - - // REMOVED: Headless detection - no longer needed (license system removed) - - // --- GLOBAL API --- - window.sentience = { - // 1. Geometry snapshot (existing) - snapshot: async (options = {}) => { - if (!wasmModule) return { error: "WASM not ready" }; - - const rawData = []; - // Remove textMap as we include text in rawData - window.sentience_registry = []; - - const nodes = getAllElements(); - - nodes.forEach((el, idx) => { - if (!el.getBoundingClientRect) return; - const rect = el.getBoundingClientRect(); - if (rect.width < 5 || rect.height < 5) return; - - window.sentience_registry[idx] = el; - - // Calculate properties for Fat Payload - const textVal = getText(el); - const inView = isInViewport(rect); - // Only check occlusion if visible (Optimization) - const occluded = inView ? isOccluded(el, rect) : false; - - const style = window.getComputedStyle(el); - rawData.push({ - id: idx, - tag: el.tagName.toLowerCase(), - rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height }, - styles: { - display: style.display, - visibility: style.visibility, - opacity: style.opacity, - z_index: style.zIndex || "0", - bg_color: style.backgroundColor, - color: style.color, - cursor: style.cursor, - font_weight: style.fontWeight, - font_size: style.fontSize - }, - attributes: { - role: el.getAttribute('role'), - type_: el.getAttribute('type'), - aria_label: el.getAttribute('aria-label'), - href: el.href, - class: el.className - }, - // Pass to WASM - text: textVal || null, - in_viewport: inView, - is_occluded: occluded - }); - }); - - // FREE TIER: No license checks - extension provides basic geometry data - // Pro/Enterprise tiers will be handled server-side (future work) - - // 1. Get Geometry from WASM - let result; - try { - if (options.limit || options.filter) { - result = wasmModule.analyze_page_with_options(rawData, options); - } else { - result = wasmModule.analyze_page(rawData); - } - } catch (e) { - return { status: "error", error: e.message }; - } - - // Hydration step removed as WASM now returns populated structs - - // Capture Screenshot - let screenshot = null; - if (options.screenshot) { - screenshot = await captureScreenshot(options.screenshot); - } - - // C. Clean up null/undefined fields to save tokens (Your existing cleaner) - const cleanElement = (obj) => { - if (Array.isArray(obj)) { - return obj.map(cleanElement); - } else if (obj !== null && typeof obj === 'object') { - const cleaned = {}; - for (const [key, value] of Object.entries(obj)) { - // Keep boolean false for critical flags if desired, or remove to match Rust defaults - if (value !== null && value !== undefined) { - cleaned[key] = cleanElement(value); - } - } - return cleaned; - } - return obj; - }; - - const cleanedElements = cleanElement(result); - - return { - status: "success", - url: window.location.href, - elements: cleanedElements, - raw_elements: rawData, // Include raw data for server-side processing (safe to expose - no proprietary value) - screenshot: screenshot - }; - }, - // 2. Read Content (New) - read: (options = {}) => { - const format = options.format || 'raw'; // 'raw', 'text', or 'markdown' - let content; - - if (format === 'raw') { - // Return raw HTML suitable for Turndown or other Node.js libraries - content = getRawHTML(document.body); - } else if (format === 'markdown') { - // Return lightweight markdown conversion - content = convertToMarkdown(document.body); - } else { - // Default to text - content = convertToText(document.body); - } - - return { - status: "success", - url: window.location.href, - format: format, - content: content, - length: content.length - }; - }, - - // 3. Action - click: (id) => { - const el = window.sentience_registry[id]; - if (el) { el.click(); el.focus(); return true; } - return false; - } - }; -})(); \ No newline at end of file +Not Found \ No newline at end of file diff --git a/sentience/extension/manifest.json b/sentience/extension/manifest.json index 9d979cb..8537307 100644 --- a/sentience/extension/manifest.json +++ b/sentience/extension/manifest.json @@ -1,30 +1 @@ -{ - "manifest_version": 3, - "name": "Sentience Semantic Visual Grounding Extractor", - "version": "1.0.5", - "description": "Extract semantic visual grounding data from web pages", - "permissions": ["activeTab", "scripting"], - "host_permissions": [""], - "web_accessible_resources": [ - { - "resources": ["pkg/*"], - "matches": [""] - } - ], - "content_scripts": [ - { - "matches": [""], - "js": ["content.js"], - "run_at": "document_start" - }, - { - "matches": [""], - "js": ["injected_api.js"], - "run_at": "document_idle", - "world": "MAIN" - } - ], - "content_security_policy": { - "extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'" - } -} \ No newline at end of file +Not Found \ No newline at end of file diff --git a/sentience/extension/pkg/sentience_core.d.ts b/sentience/extension/pkg/sentience_core.d.ts index 017160d..8537307 100644 --- a/sentience/extension/pkg/sentience_core.d.ts +++ b/sentience/extension/pkg/sentience_core.d.ts @@ -1,42 +1 @@ -/* tslint:disable */ -/* eslint-disable */ - -export function analyze_page(val: any): any; - -export function analyze_page_with_options(val: any, options: any): any; - -export function decide_and_act(_raw_elements: any): void; - -export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; - -export interface InitOutput { - readonly memory: WebAssembly.Memory; - readonly analyze_page: (a: number) => number; - readonly analyze_page_with_options: (a: number, b: number) => number; - readonly decide_and_act: (a: number) => void; - readonly __wbindgen_export: (a: number, b: number) => number; - readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number; - readonly __wbindgen_export3: (a: number) => void; -} - -export type SyncInitInput = BufferSource | WebAssembly.Module; - -/** -* Instantiates the given `module`, which can either be bytes or -* a precompiled `WebAssembly.Module`. -* -* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated. -* -* @returns {InitOutput} -*/ -export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput; - -/** -* If `module_or_path` is {RequestInfo} or {URL}, makes a request and -* for everything else, calls `WebAssembly.instantiate` directly. -* -* @param {{ module_or_path: InitInput | Promise }} module_or_path - Passing `InitInput` directly is deprecated. -* -* @returns {Promise} -*/ -export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise } | InitInput | Promise): Promise; +Not Found \ No newline at end of file diff --git a/sentience/extension/pkg/sentience_core.js b/sentience/extension/pkg/sentience_core.js index bb44be7..8537307 100644 --- a/sentience/extension/pkg/sentience_core.js +++ b/sentience/extension/pkg/sentience_core.js @@ -1,513 +1 @@ -let wasm; - -function addHeapObject(obj) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - - heap[idx] = obj; - return idx; -} - -function debugString(val) { - // primitive types - const type = typeof val; - if (type == 'number' || type == 'boolean' || val == null) { - return `${val}`; - } - if (type == 'string') { - return `"${val}"`; - } - if (type == 'symbol') { - const description = val.description; - if (description == null) { - return 'Symbol'; - } else { - return `Symbol(${description})`; - } - } - if (type == 'function') { - const name = val.name; - if (typeof name == 'string' && name.length > 0) { - return `Function(${name})`; - } else { - return 'Function'; - } - } - // objects - if (Array.isArray(val)) { - const length = val.length; - let debug = '['; - if (length > 0) { - debug += debugString(val[0]); - } - for(let i = 1; i < length; i++) { - debug += ', ' + debugString(val[i]); - } - debug += ']'; - return debug; - } - // Test for built-in - const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); - let className; - if (builtInMatches && builtInMatches.length > 1) { - className = builtInMatches[1]; - } else { - // Failed to match the standard '[object ClassName]' - return toString.call(val); - } - if (className == 'Object') { - // we're a user defined class or Object - // JSON.stringify avoids problems with cycles, and is generally much - // easier than looping through ownProperties of `val`. - try { - return 'Object(' + JSON.stringify(val) + ')'; - } catch (_) { - return 'Object'; - } - } - // errors - if (val instanceof Error) { - return `${val.name}: ${val.message}\n${val.stack}`; - } - // TODO we could test for more things here, like `Set`s and `Map`s. - return className; -} - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function getArrayU8FromWasm0(ptr, len) { - ptr = ptr >>> 0; - return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); -} - -let cachedDataViewMemory0 = null; -function getDataViewMemory0() { - if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { - cachedDataViewMemory0 = new DataView(wasm.memory.buffer); - } - return cachedDataViewMemory0; -} - -function getStringFromWasm0(ptr, len) { - ptr = ptr >>> 0; - return decodeText(ptr, len); -} - -let cachedUint8ArrayMemory0 = null; -function getUint8ArrayMemory0() { - if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { - cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); - } - return cachedUint8ArrayMemory0; -} - -function getObject(idx) { return heap[idx]; } - -function handleError(f, args) { - try { - return f.apply(this, args); - } catch (e) { - wasm.__wbindgen_export3(addHeapObject(e)); - } -} - -let heap = new Array(128).fill(undefined); -heap.push(undefined, null, true, false); - -let heap_next = heap.length; - -function isLikeNone(x) { - return x === undefined || x === null; -} - -function passStringToWasm0(arg, malloc, realloc) { - if (realloc === undefined) { - const buf = cachedTextEncoder.encode(arg); - const ptr = malloc(buf.length, 1) >>> 0; - getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); - WASM_VECTOR_LEN = buf.length; - return ptr; - } - - let len = arg.length; - let ptr = malloc(len, 1) >>> 0; - - const mem = getUint8ArrayMemory0(); - - let offset = 0; - - for (; offset < len; offset++) { - const code = arg.charCodeAt(offset); - if (code > 0x7F) break; - mem[ptr + offset] = code; - } - if (offset !== len) { - if (offset !== 0) { - arg = arg.slice(offset); - } - ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; - const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); - const ret = cachedTextEncoder.encodeInto(arg, view); - - offset += ret.written; - ptr = realloc(ptr, len, offset, 1) >>> 0; - } - - WASM_VECTOR_LEN = offset; - return ptr; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - -let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); -cachedTextDecoder.decode(); -const MAX_SAFARI_DECODE_BYTES = 2146435072; -let numBytesDecoded = 0; -function decodeText(ptr, len) { - numBytesDecoded += len; - if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) { - cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); - cachedTextDecoder.decode(); - numBytesDecoded = len; - } - return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); -} - -const cachedTextEncoder = new TextEncoder(); - -if (!('encodeInto' in cachedTextEncoder)) { - cachedTextEncoder.encodeInto = function (arg, view) { - const buf = cachedTextEncoder.encode(arg); - view.set(buf); - return { - read: arg.length, - written: buf.length - }; - } -} - -let WASM_VECTOR_LEN = 0; - -/** - * @param {any} val - * @returns {any} - */ -export function analyze_page(val) { - const ret = wasm.analyze_page(addHeapObject(val)); - return takeObject(ret); -} - -/** - * @param {any} val - * @param {any} options - * @returns {any} - */ -export function analyze_page_with_options(val, options) { - const ret = wasm.analyze_page_with_options(addHeapObject(val), addHeapObject(options)); - return takeObject(ret); -} - -/** - * @param {any} _raw_elements - */ -export function decide_and_act(_raw_elements) { - wasm.decide_and_act(addHeapObject(_raw_elements)); -} - -const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']); - -async function __wbg_load(module, imports) { - if (typeof Response === 'function' && module instanceof Response) { - if (typeof WebAssembly.instantiateStreaming === 'function') { - try { - return await WebAssembly.instantiateStreaming(module, imports); - } catch (e) { - const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type); - - if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') { - console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); - - } else { - throw e; - } - } - } - - const bytes = await module.arrayBuffer(); - return await WebAssembly.instantiate(bytes, imports); - } else { - const instance = await WebAssembly.instantiate(module, imports); - - if (instance instanceof WebAssembly.Instance) { - return { instance, module }; - } else { - return instance; - } - } -} - -function __wbg_get_imports() { - const imports = {}; - imports.wbg = {}; - imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) { - const ret = Error(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }; - imports.wbg.__wbg_Number_2d1dcfcf4ec51736 = function(arg0) { - const ret = Number(getObject(arg0)); - return ret; - }; - imports.wbg.__wbg___wbindgen_bigint_get_as_i64_6e32f5e6aff02e1d = function(arg0, arg1) { - const v = getObject(arg1); - const ret = typeof(v) === 'bigint' ? v : undefined; - getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true); - getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true); - }; - imports.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b = function(arg0) { - const v = getObject(arg0); - const ret = typeof(v) === 'boolean' ? v : undefined; - return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0; - }; - imports.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6 = function(arg0, arg1) { - const ret = debugString(getObject(arg1)); - const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2); - const len1 = WASM_VECTOR_LEN; - getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); - getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); - }; - imports.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317 = function(arg0, arg1) { - const ret = getObject(arg0) in getObject(arg1); - return ret; - }; - imports.wbg.__wbg___wbindgen_is_bigint_0e1a2e3f55cfae27 = function(arg0) { - const ret = typeof(getObject(arg0)) === 'bigint'; - return ret; - }; - imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) { - const ret = typeof(getObject(arg0)) === 'function'; - return ret; - }; - imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) { - const val = getObject(arg0); - const ret = typeof(val) === 'object' && val !== null; - return ret; - }; - imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) { - const ret = getObject(arg0) === undefined; - return ret; - }; - imports.wbg.__wbg___wbindgen_jsval_eq_b6101cc9cef1fe36 = function(arg0, arg1) { - const ret = getObject(arg0) === getObject(arg1); - return ret; - }; - imports.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d = function(arg0, arg1) { - const ret = getObject(arg0) == getObject(arg1); - return ret; - }; - imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'number' ? obj : undefined; - getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true); - getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true); - }; - imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'string' ? obj : undefined; - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2); - var len1 = WASM_VECTOR_LEN; - getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); - getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); - }; - imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) { - throw new Error(getStringFromWasm0(arg0, arg1)); - }; - imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) { - const ret = getObject(arg0).call(getObject(arg1)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_done_62ea16af4ce34b24 = function(arg0) { - const ret = getObject(arg0).done; - return ret; - }; - imports.wbg.__wbg_get_6b7bd52aca3f9671 = function(arg0, arg1) { - const ret = getObject(arg0)[arg1 >>> 0]; - return addHeapObject(ret); - }; - imports.wbg.__wbg_get_af9dab7e9603ea93 = function() { return handleError(function (arg0, arg1) { - const ret = Reflect.get(getObject(arg0), getObject(arg1)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe = function(arg0, arg1) { - const ret = getObject(arg0)[getObject(arg1)]; - return addHeapObject(ret); - }; - imports.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355 = function(arg0) { - let result; - try { - result = getObject(arg0) instanceof ArrayBuffer; - } catch (_) { - result = false; - } - const ret = result; - return ret; - }; - imports.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434 = function(arg0) { - let result; - try { - result = getObject(arg0) instanceof Uint8Array; - } catch (_) { - result = false; - } - const ret = result; - return ret; - }; - imports.wbg.__wbg_isArray_51fd9e6422c0a395 = function(arg0) { - const ret = Array.isArray(getObject(arg0)); - return ret; - }; - imports.wbg.__wbg_isSafeInteger_ae7d3f054d55fa16 = function(arg0) { - const ret = Number.isSafeInteger(getObject(arg0)); - return ret; - }; - imports.wbg.__wbg_iterator_27b7c8b35ab3e86b = function() { - const ret = Symbol.iterator; - return addHeapObject(ret); - }; - imports.wbg.__wbg_js_click_element_2fe1e774f3d232c7 = function(arg0) { - js_click_element(arg0); - }; - imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) { - const ret = getObject(arg0).length; - return ret; - }; - imports.wbg.__wbg_length_d45040a40c570362 = function(arg0) { - const ret = getObject(arg0).length; - return ret; - }; - imports.wbg.__wbg_new_1ba21ce319a06297 = function() { - const ret = new Object(); - return addHeapObject(ret); - }; - imports.wbg.__wbg_new_25f239778d6112b9 = function() { - const ret = new Array(); - return addHeapObject(ret); - }; - imports.wbg.__wbg_new_6421f6084cc5bc5a = function(arg0) { - const ret = new Uint8Array(getObject(arg0)); - return addHeapObject(ret); - }; - imports.wbg.__wbg_next_138a17bbf04e926c = function(arg0) { - const ret = getObject(arg0).next; - return addHeapObject(ret); - }; - imports.wbg.__wbg_next_3cfe5c0fe2a4cc53 = function() { return handleError(function (arg0) { - const ret = getObject(arg0).next(); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) { - Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2)); - }; - imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) { - getObject(arg0)[takeObject(arg1)] = takeObject(arg2); - }; - imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) { - getObject(arg0)[arg1 >>> 0] = takeObject(arg2); - }; - imports.wbg.__wbg_value_57b7b035e117f7ee = function(arg0) { - const ret = getObject(arg0).value; - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) { - // Cast intrinsic for `Ref(String) -> Externref`. - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) { - // Cast intrinsic for `U64 -> Externref`. - const ret = BigInt.asUintN(64, arg0); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) { - // Cast intrinsic for `F64 -> Externref`. - const ret = arg0; - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_object_clone_ref = function(arg0) { - const ret = getObject(arg0); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); - }; - - return imports; -} - -function __wbg_finalize_init(instance, module) { - wasm = instance.exports; - __wbg_init.__wbindgen_wasm_module = module; - cachedDataViewMemory0 = null; - cachedUint8ArrayMemory0 = null; - - - - return wasm; -} - -function initSync(module) { - if (wasm !== undefined) return wasm; - - - if (typeof module !== 'undefined') { - if (Object.getPrototypeOf(module) === Object.prototype) { - ({module} = module) - } else { - console.warn('using deprecated parameters for `initSync()`; pass a single object instead') - } - } - - const imports = __wbg_get_imports(); - if (!(module instanceof WebAssembly.Module)) { - module = new WebAssembly.Module(module); - } - const instance = new WebAssembly.Instance(module, imports); - return __wbg_finalize_init(instance, module); -} - -async function __wbg_init(module_or_path) { - if (wasm !== undefined) return wasm; - - - if (typeof module_or_path !== 'undefined') { - if (Object.getPrototypeOf(module_or_path) === Object.prototype) { - ({module_or_path} = module_or_path) - } else { - console.warn('using deprecated parameters for the initialization function; pass a single object instead') - } - } - - if (typeof module_or_path === 'undefined') { - module_or_path = new URL('sentience_core_bg.wasm', import.meta.url); - } - const imports = __wbg_get_imports(); - - if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { - module_or_path = fetch(module_or_path); - } - - const { instance, module } = await __wbg_load(await module_or_path, imports); - - return __wbg_finalize_init(instance, module); -} - -export { initSync }; -export default __wbg_init; +Not Found \ No newline at end of file diff --git a/sentience/extension/pkg/sentience_core_bg.wasm b/sentience/extension/pkg/sentience_core_bg.wasm index 10a312c..8537307 100644 Binary files a/sentience/extension/pkg/sentience_core_bg.wasm and b/sentience/extension/pkg/sentience_core_bg.wasm differ diff --git a/sentience/extension/pkg/sentience_core_bg.wasm.d.ts b/sentience/extension/pkg/sentience_core_bg.wasm.d.ts index 3544143..8537307 100644 --- a/sentience/extension/pkg/sentience_core_bg.wasm.d.ts +++ b/sentience/extension/pkg/sentience_core_bg.wasm.d.ts @@ -1,9 +1 @@ -/* tslint:disable */ -/* eslint-disable */ -export const memory: WebAssembly.Memory; -export const analyze_page: (a: number) => number; -export const analyze_page_with_options: (a: number, b: number) => number; -export const decide_and_act: (a: number) => void; -export const __wbindgen_export: (a: number, b: number) => number; -export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number; -export const __wbindgen_export3: (a: number) => void; +Not Found \ No newline at end of file