@minded-ai/mindedjs 1.0.0-ec2-beta-6 → 1.0.0-ec2-beta-7
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.
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Browser Task Executor with Screenshot Capture Support
|
|
3
3
|
|
|
4
|
-
This script runs browser automation tasks using browser-use and
|
|
5
|
-
screenshots at the end of each step, uploading them to S3.
|
|
6
|
-
|
|
7
|
-
Environment Variables for Screenshots:
|
|
8
|
-
- SCREENSHOT_S3_BUCKET: S3 bucket name (default: 'global-development-agentsforce')
|
|
9
|
-
- SCREENSHOT_S3_PREFIX: S3 key prefix (default: 'browser-use-runs-screenshots/')
|
|
10
|
-
- AWS_REGION: AWS region for S3 (default: 'us-east-1')
|
|
11
|
-
|
|
12
|
-
AWS credentials should be configured via standard AWS SDK methods.
|
|
4
|
+
This script runs browser automation tasks using browser-use and can capture
|
|
5
|
+
screenshots at the end of each step, uploading them to S3 when configured.
|
|
13
6
|
"""
|
|
14
7
|
|
|
15
8
|
import asyncio
|
|
@@ -90,15 +83,13 @@ class ScreenshotCapture:
|
|
|
90
83
|
# Get current page
|
|
91
84
|
page = await agent.browser_session.get_current_page()
|
|
92
85
|
|
|
93
|
-
# Get current URL for
|
|
86
|
+
# Get current URL for logging (browser-use might use method instead of property)
|
|
94
87
|
try:
|
|
95
|
-
# Try as property first
|
|
96
88
|
current_url = page.url if hasattr(page, 'url') else page.url()
|
|
97
89
|
except:
|
|
98
|
-
# Fallback if URL is not accessible
|
|
99
90
|
current_url = "unknown"
|
|
100
91
|
|
|
101
|
-
logger.info(f"📸 Taking
|
|
92
|
+
logger.info(f"📸 Taking screenshot at: {current_url}")
|
|
102
93
|
|
|
103
94
|
# Update step counter
|
|
104
95
|
step_number = self.step_counter
|
|
@@ -107,45 +98,30 @@ class ScreenshotCapture:
|
|
|
107
98
|
# Take screenshot - browser-use takes viewport by default
|
|
108
99
|
screenshot_data = await page.screenshot()
|
|
109
100
|
|
|
110
|
-
# Ensure we have bytes - browser-use might return
|
|
101
|
+
# Ensure we have bytes - browser-use might return base64 string or bytes
|
|
111
102
|
if isinstance(screenshot_data, bytes):
|
|
112
103
|
screenshot_bytes = screenshot_data
|
|
113
104
|
elif isinstance(screenshot_data, str):
|
|
114
|
-
# If it's base64 encoded string
|
|
105
|
+
# If it's base64 encoded string, decode it
|
|
115
106
|
screenshot_bytes = base64.b64decode(screenshot_data)
|
|
116
107
|
else:
|
|
117
108
|
# Try to get bytes from whatever format it is
|
|
118
109
|
screenshot_bytes = bytes(screenshot_data)
|
|
119
110
|
|
|
120
|
-
logger.debug(f"Screenshot data type: {type(screenshot_data)}, size: {len(screenshot_bytes)} bytes")
|
|
121
|
-
|
|
122
111
|
# Generate filename with metadata
|
|
123
112
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")[:-3]
|
|
124
113
|
filename = f"{self.session_id}/step_{step_number:04d}_{timestamp}.png"
|
|
125
114
|
|
|
126
|
-
# Optional: Save to temp file for debugging (like Lambda does)
|
|
127
|
-
if os.getenv('DEBUG_SCREENSHOTS') == 'true':
|
|
128
|
-
temp_dir = Path("/tmp/screenshots")
|
|
129
|
-
temp_dir.mkdir(exist_ok=True, parents=True)
|
|
130
|
-
temp_path = temp_dir / f"step_{step_number:04d}_{timestamp}.png"
|
|
131
|
-
with open(temp_path, "wb") as f:
|
|
132
|
-
f.write(screenshot_bytes)
|
|
133
|
-
logger.debug(f"💾 Debug: Saved screenshot to: {temp_path}")
|
|
134
|
-
|
|
135
115
|
# Upload to S3
|
|
136
116
|
s3_key = f"{self.s3_prefix}{filename}"
|
|
137
117
|
|
|
138
118
|
try:
|
|
139
|
-
# Verify we have valid
|
|
119
|
+
# Verify we have valid data before uploading
|
|
140
120
|
if not screenshot_bytes or len(screenshot_bytes) == 0:
|
|
141
121
|
logger.error(f"❌ Screenshot bytes are empty!")
|
|
142
122
|
return
|
|
143
123
|
|
|
144
|
-
#
|
|
145
|
-
if len(screenshot_bytes) > 4 and screenshot_bytes[:4] != b'\x89PNG':
|
|
146
|
-
logger.warning(f"⚠️ Screenshot may not be valid PNG format. First 4 bytes: {screenshot_bytes[:4].hex()}")
|
|
147
|
-
|
|
148
|
-
# Upload with KMS encryption if required by bucket (matching Lambda implementation)
|
|
124
|
+
# Upload to S3 with KMS encryption
|
|
149
125
|
self.s3_client.put_object(
|
|
150
126
|
Bucket=self.s3_bucket,
|
|
151
127
|
Key=s3_key,
|
|
@@ -153,11 +129,10 @@ class ScreenshotCapture:
|
|
|
153
129
|
ContentType='image/png',
|
|
154
130
|
ServerSideEncryption='aws:kms',
|
|
155
131
|
Tagging='retention=30d'
|
|
156
|
-
# Using bucket's default KMS key
|
|
157
132
|
)
|
|
158
133
|
|
|
159
134
|
s3_url = f"s3://{self.s3_bucket}/{s3_key}"
|
|
160
|
-
logger.info(f"✅ Screenshot uploaded: {s3_url}
|
|
135
|
+
logger.info(f"✅ Screenshot uploaded: {s3_url}")
|
|
161
136
|
|
|
162
137
|
except self.ClientError as e:
|
|
163
138
|
logger.error(f"❌ Failed to upload screenshot to S3: {str(e)}")
|
package/package.json
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Browser Task Executor with Screenshot Capture Support
|
|
3
3
|
|
|
4
|
-
This script runs browser automation tasks using browser-use and
|
|
5
|
-
screenshots at the end of each step, uploading them to S3.
|
|
6
|
-
|
|
7
|
-
Environment Variables for Screenshots:
|
|
8
|
-
- SCREENSHOT_S3_BUCKET: S3 bucket name (default: 'global-development-agentsforce')
|
|
9
|
-
- SCREENSHOT_S3_PREFIX: S3 key prefix (default: 'browser-use-runs-screenshots/')
|
|
10
|
-
- AWS_REGION: AWS region for S3 (default: 'us-east-1')
|
|
11
|
-
|
|
12
|
-
AWS credentials should be configured via standard AWS SDK methods.
|
|
4
|
+
This script runs browser automation tasks using browser-use and can capture
|
|
5
|
+
screenshots at the end of each step, uploading them to S3 when configured.
|
|
13
6
|
"""
|
|
14
7
|
|
|
15
8
|
import asyncio
|
|
@@ -90,15 +83,13 @@ class ScreenshotCapture:
|
|
|
90
83
|
# Get current page
|
|
91
84
|
page = await agent.browser_session.get_current_page()
|
|
92
85
|
|
|
93
|
-
# Get current URL for
|
|
86
|
+
# Get current URL for logging (browser-use might use method instead of property)
|
|
94
87
|
try:
|
|
95
|
-
# Try as property first
|
|
96
88
|
current_url = page.url if hasattr(page, 'url') else page.url()
|
|
97
89
|
except:
|
|
98
|
-
# Fallback if URL is not accessible
|
|
99
90
|
current_url = "unknown"
|
|
100
91
|
|
|
101
|
-
logger.info(f"📸 Taking
|
|
92
|
+
logger.info(f"📸 Taking screenshot at: {current_url}")
|
|
102
93
|
|
|
103
94
|
# Update step counter
|
|
104
95
|
step_number = self.step_counter
|
|
@@ -107,45 +98,30 @@ class ScreenshotCapture:
|
|
|
107
98
|
# Take screenshot - browser-use takes viewport by default
|
|
108
99
|
screenshot_data = await page.screenshot()
|
|
109
100
|
|
|
110
|
-
# Ensure we have bytes - browser-use might return
|
|
101
|
+
# Ensure we have bytes - browser-use might return base64 string or bytes
|
|
111
102
|
if isinstance(screenshot_data, bytes):
|
|
112
103
|
screenshot_bytes = screenshot_data
|
|
113
104
|
elif isinstance(screenshot_data, str):
|
|
114
|
-
# If it's base64 encoded string
|
|
105
|
+
# If it's base64 encoded string, decode it
|
|
115
106
|
screenshot_bytes = base64.b64decode(screenshot_data)
|
|
116
107
|
else:
|
|
117
108
|
# Try to get bytes from whatever format it is
|
|
118
109
|
screenshot_bytes = bytes(screenshot_data)
|
|
119
110
|
|
|
120
|
-
logger.debug(f"Screenshot data type: {type(screenshot_data)}, size: {len(screenshot_bytes)} bytes")
|
|
121
|
-
|
|
122
111
|
# Generate filename with metadata
|
|
123
112
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_%f")[:-3]
|
|
124
113
|
filename = f"{self.session_id}/step_{step_number:04d}_{timestamp}.png"
|
|
125
114
|
|
|
126
|
-
# Optional: Save to temp file for debugging (like Lambda does)
|
|
127
|
-
if os.getenv('DEBUG_SCREENSHOTS') == 'true':
|
|
128
|
-
temp_dir = Path("/tmp/screenshots")
|
|
129
|
-
temp_dir.mkdir(exist_ok=True, parents=True)
|
|
130
|
-
temp_path = temp_dir / f"step_{step_number:04d}_{timestamp}.png"
|
|
131
|
-
with open(temp_path, "wb") as f:
|
|
132
|
-
f.write(screenshot_bytes)
|
|
133
|
-
logger.debug(f"💾 Debug: Saved screenshot to: {temp_path}")
|
|
134
|
-
|
|
135
115
|
# Upload to S3
|
|
136
116
|
s3_key = f"{self.s3_prefix}{filename}"
|
|
137
117
|
|
|
138
118
|
try:
|
|
139
|
-
# Verify we have valid
|
|
119
|
+
# Verify we have valid data before uploading
|
|
140
120
|
if not screenshot_bytes or len(screenshot_bytes) == 0:
|
|
141
121
|
logger.error(f"❌ Screenshot bytes are empty!")
|
|
142
122
|
return
|
|
143
123
|
|
|
144
|
-
#
|
|
145
|
-
if len(screenshot_bytes) > 4 and screenshot_bytes[:4] != b'\x89PNG':
|
|
146
|
-
logger.warning(f"⚠️ Screenshot may not be valid PNG format. First 4 bytes: {screenshot_bytes[:4].hex()}")
|
|
147
|
-
|
|
148
|
-
# Upload with KMS encryption if required by bucket (matching Lambda implementation)
|
|
124
|
+
# Upload to S3 with KMS encryption
|
|
149
125
|
self.s3_client.put_object(
|
|
150
126
|
Bucket=self.s3_bucket,
|
|
151
127
|
Key=s3_key,
|
|
@@ -153,11 +129,10 @@ class ScreenshotCapture:
|
|
|
153
129
|
ContentType='image/png',
|
|
154
130
|
ServerSideEncryption='aws:kms',
|
|
155
131
|
Tagging='retention=30d'
|
|
156
|
-
# Using bucket's default KMS key
|
|
157
132
|
)
|
|
158
133
|
|
|
159
134
|
s3_url = f"s3://{self.s3_bucket}/{s3_key}"
|
|
160
|
-
logger.info(f"✅ Screenshot uploaded: {s3_url}
|
|
135
|
+
logger.info(f"✅ Screenshot uploaded: {s3_url}")
|
|
161
136
|
|
|
162
137
|
except self.ClientError as e:
|
|
163
138
|
logger.error(f"❌ Failed to upload screenshot to S3: {str(e)}")
|