Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

test: cover extension startup and additive merge in E2E

Luigi Agosti74c924fc2553
diff --git a/tests/e2e/config/pinchtab.json b/tests/e2e/config/pinchtab.json
index c7364468..5ac7755e 100644
--- a/tests/e2e/config/pinchtab.json
+++ b/tests/e2e/config/pinchtab.json
@@ -4,7 +4,10 @@
"port": "9999"
},
"browser": {
- "extraFlags": "--no-sandbox --disable-dev-shm-usage"
+ "extraFlags": "--no-sandbox --disable-dev-shm-usage",
+ "extensionPaths": [
+ "/extensions/test-extension"
+ ]
},
"instanceDefaults": {
"maxTabs": 10
diff --git a/tests/e2e/docker-compose-cli.yml b/tests/e2e/docker-compose-cli.yml
index fd0d35b1..d138c1c8 100644
--- a/tests/e2e/docker-compose-cli.yml
+++ b/tests/e2e/docker-compose-cli.yml
@@ -9,6 +9,7 @@ services:
PINCHTAB_PORT: "9999"
volumes:
- ./config/pinchtab.json:/config/pinchtab.json:ro
+ - ./fixtures/test-extension:/extensions/test-extension:ro
ports:
- "9999:9999"
shm_size: '2gb'
diff --git a/tests/e2e/docker-compose.yml b/tests/e2e/docker-compose.yml
index 16f08faa..eed14405 100644
--- a/tests/e2e/docker-compose.yml
+++ b/tests/e2e/docker-compose.yml
@@ -9,6 +9,8 @@ services:
PINCHTAB_PORT: "9999"
volumes:
- ./config/pinchtab.json:/config/pinchtab.json:ro
+ - ./fixtures/test-extension:/extensions/test-extension
+ - ./fixtures/test-extension-api:/extensions/test-extension-api
ports:
- "9999:9999"
# Chrome needs more shared memory in Docker
diff --git a/tests/e2e/fixtures/test-extension-api/manifest.json b/tests/e2e/fixtures/test-extension-api/manifest.json
new file mode 100755
index 00000000..77d259ee
--- /dev/null
+++ b/tests/e2e/fixtures/test-extension-api/manifest.json
@@ -0,0 +1,14 @@
+{
+ "manifest_version": 3,
+ "name": "PinchTab API Test Extension",
+ "version": "1.0.0",
+ "description": "Second extension for testing additive loading",
+ "host_permissions": ["*://*/*"],
+ "content_scripts": [
+ {
+ "matches": ["*://*/*"],
+ "js": ["content.js"],
+ "run_at": "document_start"
+ }
+ ]
+}
diff --git a/tests/e2e/fixtures/test-extension/manifest.json b/tests/e2e/fixtures/test-extension/manifest.json
new file mode 100755
index 00000000..166a7f03
--- /dev/null
+++ b/tests/e2e/fixtures/test-extension/manifest.json
@@ -0,0 +1,14 @@
+{
+ "manifest_version": 3,
+ "name": "PinchTab Test Extension",
+ "version": "1.0.0",
+ "description": "Minimal extension for E2E testing",
+ "host_permissions": ["*://*/*"],
+ "content_scripts": [
+ {
+ "matches": ["*://*/*"],
+ "js": ["content.js"],
+ "run_at": "document_start"
+ }
+ ]
+}
diff --git a/tests/e2e/scenarios/41-extensions.sh b/tests/e2e/scenarios/41-extensions.sh
new file mode 100755
index 00000000..e70d1764
--- /dev/null
+++ b/tests/e2e/scenarios/41-extensions.sh
@@ -0,0 +1,137 @@
+#!/bin/bash
+# Test: Browser extension loading
+# Verifies that extension paths reach Chrome startup reliably in CI.
+source "$(dirname "$0")/common.sh"
+
+ORCH_URL=$PINCHTAB_URL
+ORIG_URL=$PINCHTAB_URL
+
+assert_instance_logs_poll() {
+ local inst_id="$1"
+ local needle="$2"
+ local desc="$3"
+ local attempts="${4:-10}"
+ local delay="${5:-1}"
+
+ local i
+ for i in $(seq 1 "$attempts"); do
+ PINCHTAB_URL=$ORCH_URL pt_get "/instances/${inst_id}/logs" >/dev/null
+ if [[ "$HTTP_STATUS" =~ ^2 ]] && echo "$RESULT" | grep -Fq "$needle"; then
+ echo -e " ${GREEN}✓${NC} $desc"
+ ((ASSERTIONS_PASSED++)) || true
+ return 0
+ fi
+ sleep "$delay"
+ done
+
+ echo -e " ${RED}✗${NC} $desc (missing: $needle)"
+ ((ASSERTIONS_FAILED++)) || true
+ return 1
+}
+
+print_extension_hints() {
+ local inst_id="${1:-}"
+ echo ""
+ echo " ${YELLOW}${BOLD}🔍 Troubleshooting Extension Failure:${NC}"
+ echo " - Check if /extensions/test-extension exists and is readable in the pinchtab container."
+ echo " - Check Manifest V3 host_permissions matches: [\"*://*/*\"]"
+ if [ -n "$inst_id" ]; then
+ PINCHTAB_URL=$ORCH_URL pt_get "/instances/${inst_id}/logs" >/dev/null
+ echo " - Recent instance log tail:"
+ printf '%s\n' "$RESULT" | tail -n 12 | sed 's/^/ /'
+ fi
+ echo ""
+}
+
+# --- T1: Default instance loads configured extension path ---
+start_test "Extension config: default instance loads configured extension path"
+
+pt_get /instances
+assert_ok "list instances"
+DEFAULT_INST_ID=$(echo "$RESULT" | jq -r '.[] | select(.profileName == "default") | .id' | head -n 1)
+if [ -n "$DEFAULT_INST_ID" ] && [ "$DEFAULT_INST_ID" != "null" ]; then
+ echo -e " ${GREEN}✓${NC} default instance present"
+ ((ASSERTIONS_PASSED++)) || true
+else
+ echo -e " ${RED}✗${NC} default instance present"
+ ((ASSERTIONS_FAILED++)) || true
+fi
+
+pt_post /navigate "{\"url\":\"${FIXTURES_URL}/index.html\"}"
+assert_ok "navigate"
+
+DEFAULT_LOG_PASS=1
+if [ -n "$DEFAULT_INST_ID" ] && [ "$DEFAULT_INST_ID" != "null" ]; then
+ assert_instance_logs_poll \
+ "$DEFAULT_INST_ID" \
+ "loading extensions paths=/extensions/test-extension" \
+ "default instance logs configured extension path"
+ DEFAULT_LOG_PASS=$?
+
+ assert_instance_logs_poll \
+ "$DEFAULT_INST_ID" \
+ "chrome initialized successfully" \
+ "default instance chrome initialized"
+fi
+
+if [ $DEFAULT_LOG_PASS -ne 0 ]; then
+ print_extension_hints "$DEFAULT_INST_ID"
+fi
+
+end_test
+
+# --- T2: Instance start with extension via API ---
+start_test "Extension config: instance start accepts extensionPaths"
+
+pt_post /instances/start '{"extensionPaths":["/extensions/test-extension"]}'
+assert_ok "instance start with extension"
+INST_ID=$(echo "$RESULT" | jq -r '.id')
+INST_PORT=$(echo "$RESULT" | jq -r '.port')
+PINCHTAB_URL="http://pinchtab:${INST_PORT}"
+wait_for_instance_ready "${PINCHTAB_URL}"
+PINCHTAB_URL=$ORIG_URL
+
+assert_instance_logs_poll \
+ "$INST_ID" \
+ "loading extensions paths=/extensions/test-extension" \
+ "API-started instance logs extension path"
+
+end_test
+
+# --- T3: Global + API injected extensions (Additive) ---
+start_test "Additive extensions: global + API paths merged"
+
+# Start an instance that adds a SECOND extension (it should still have the global one)
+pt_post /instances/start '{"extensionPaths":["/extensions/test-extension-api"]}'
+assert_ok "instance start"
+INST_ID=$(echo "$RESULT" | jq -r '.id')
+INST_PORT=$(echo "$RESULT" | jq -r '.port')
+
+# Switch PINCHTAB_URL to the new instance's port for direct testing
+PINCHTAB_URL="http://pinchtab:${INST_PORT}"
+
+# Wait for this child instance to be ready
+wait_for_instance_ready "${PINCHTAB_URL}"
+
+# Navigate
+pt_post /navigate "{\"url\":\"${FIXTURES_URL}/index.html\"}"
+assert_ok "navigate"
+assert_instance_logs_poll \
+ "$INST_ID" \
+ "loading extensions paths=/extensions/test-extension,/extensions/test-extension-api" \
+ "child instance logs merged extension paths"
+MERGE_PASS=$?
+
+assert_instance_logs_poll \
+ "$INST_ID" \
+ "chrome initialized successfully" \
+ "child instance chrome initialized"
+
+if [ $MERGE_PASS -ne 0 ]; then
+ print_extension_hints "$INST_ID"
+fi
+
+# Restore original URL
+PINCHTAB_URL=$ORIG_URL
+
+end_test
diff --git a/tests/e2e/scenarios/common.sh b/tests/e2e/scenarios/common.sh
index 91263857..588cc95a 100755
--- a/tests/e2e/scenarios/common.sh
+++ b/tests/e2e/scenarios/common.sh
@@ -6,10 +6,12 @@ set -uo pipefail
# Colors
RED='\033[0;31m'
+ERROR="$RED"
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MUTED='\033[0;90m'
+BOLD='\033[1m'
NC='\033[0m'
# Defaults from environment
@@ -64,11 +66,15 @@ wait_for_instance_ready() {
return 1
fi
- local inst_status
- inst_status=$(curl -sf "${base_url}/health" 2>/dev/null | jq -r '.defaultInstance.status // empty' 2>/dev/null || true)
- if [ "$inst_status" = "running" ]; then
- echo -e " ${GREEN}✓${NC} instance ready at ${base_url}"
- return 0
+ local health_json
+ health_json=$(curl -sf "${base_url}/health" 2>/dev/null || true)
+ if [ -n "$health_json" ]; then
+ local inst_status
+ inst_status=$(echo "$health_json" | jq -r '.defaultInstance.status // .status // empty' 2>/dev/null || true)
+ if [ "$inst_status" = "running" ] || [ "$inst_status" = "ok" ]; then
+ echo -e " ${GREEN}✓${NC} instance ready at ${base_url}"
+ return 0
+ fi
fi
sleep 1
@@ -228,7 +234,9 @@ assert_input_not_contains() {
local forbidden="$2"
local desc="${3:-$selector should not contain '$forbidden'}"
- pt_post /evaluate -d "{\"expression\":\"document.querySelector('$selector')?.value || ''\"}"
+ local json_body
+ json_body=$(jq -n --arg sel "$selector" '{"expression": ("document.querySelector(\"" + $sel + "\")?.value || \"\"")}')
+ pt_post /evaluate "$json_body"
local value
value=$(echo "$RESULT" | jq -r '.result // empty')
@@ -291,7 +299,8 @@ pinchtab() {
shift 2
# Print the curl command in cyan so you see what's executed
- echo -e "${BLUE}→ curl -X $method ${PINCHTAB_URL}$path $@${NC}" >&2
+ # Using printf %q to better show quoted arguments
+ echo -e "${BLUE}→ curl -X $method ${PINCHTAB_URL}$path $(printf "%q " "$@")${NC}" >&2
# Execute and capture response + status
local response
@@ -303,6 +312,11 @@ pinchtab() {
RESULT=$(echo "$response" | head -n -1)
HTTP_STATUS=$(echo "$response" | tail -n 1)
+
+ # Log response body on failure for debugging
+ if [[ ! "$HTTP_STATUS" =~ ^2 ]]; then
+ echo -e "${ERROR} HTTP $HTTP_STATUS: $RESULT${NC}" >&2
+ fi
}
# Aliases for cleaner test files
@@ -621,18 +635,26 @@ assert_ref_found() {
# Evaluate with polling (for stealth/async injection)
# ================================================================
-# Poll an expression up to N times, assert result equals expected
-# Usage: assert_eval_poll "navigator.webdriver === undefined" "true" "webdriver is undefined" [attempts] [delay]
+# Poll an expression up to N times, assert result equals expected.
+# If a tab ID is provided, evaluate in that exact tab instead of the implicit current tab.
+# Usage: assert_eval_poll "navigator.webdriver === undefined" "true" "webdriver is undefined" [attempts] [delay] [tab_id]
assert_eval_poll() {
local expr="$1"
local expected="$2"
local desc="${3:-eval poll}"
local attempts="${4:-5}"
local delay="${5:-0.4}"
+ local tab_id="${6:-}"
local ok=false
for i in $(seq 1 "$attempts"); do
- pt_post /evaluate "{\"expression\":\"$expr\"}"
+ local json_body
+ if [ -n "$tab_id" ]; then
+ json_body=$(jq -n --arg expr "$expr" --arg tabId "$tab_id" '{"expression": $expr, "tabId": $tabId}')
+ else
+ json_body=$(jq -n --arg expr "$expr" '{"expression": $expr}')
+ fi
+ pt_post /evaluate "$json_body"
local actual
actual=$(echo "$RESULT" | jq -r '.result // empty' 2>/dev/null)
if [ "$actual" = "$expected" ]; then
@@ -645,9 +667,11 @@ assert_eval_poll() {
if [ "$ok" = "true" ]; then
echo -e " ${GREEN}✓${NC} $desc"
((ASSERTIONS_PASSED++)) || true
+ return 0
else
echo -e " ${RED}✗${NC} $desc (got: $actual, expected: $expected)"
((ASSERTIONS_FAILED++)) || true
+ return 1
fi
}