Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "sentienceapi"
version = "0.90.9"
version = "0.90.10"
description = "Python SDK for Sentience AI Agent Browser Automation"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
2 changes: 1 addition & 1 deletion sentience/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
)
from .wait import wait_for

__version__ = "0.90.9"
__version__ = "0.90.10"

__all__ = [
# Core SDK
Expand Down
43 changes: 43 additions & 0 deletions sentience/text_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,49 @@ def find_text_rect(
# Limit max_results to prevent performance issues
max_results = min(max_results, 100)

# CRITICAL: Wait for extension injection to complete (CSP-resistant architecture)
# The new architecture loads injected_api.js asynchronously, so window.sentience
# may not be immediately available after page load
try:
browser.page.wait_for_function(
"typeof window.sentience !== 'undefined'",
timeout=5000, # 5 second timeout
)
except Exception as e:
# Gather diagnostics if wait fails
try:
diag = browser.page.evaluate(
"""() => ({
sentience_defined: typeof window.sentience !== 'undefined',
extension_id: document.documentElement.dataset.sentienceExtensionId || 'not set',
url: window.location.href
})"""
)
except Exception:
diag = {"error": "Could not gather diagnostics"}

raise RuntimeError(
f"Sentience extension failed to inject window.sentience API. "
f"Is the extension loaded? Diagnostics: {diag}"
) from e

# Verify findTextRect method exists (for older extension versions that don't have it)
try:
has_find_text_rect = browser.page.evaluate(
"typeof window.sentience.findTextRect !== 'undefined'"
)
if not has_find_text_rect:
raise RuntimeError(
"window.sentience.findTextRect is not available. "
"Please update the Sentience extension to the latest version."
)
except RuntimeError:
raise
except Exception as e:
raise RuntimeError(
f"Failed to verify findTextRect availability: {e}"
) from e

# Call the extension's findTextRect method
result_dict = browser.page.evaluate(
"""
Expand Down