@skyramp/skyramp 1.2.39 → 1.2.41

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyramp/skyramp",
3
- "version": "1.2.39",
3
+ "version": "1.2.41",
4
4
  "description": "module for leveraging skyramp cli functionality",
5
5
  "scripts": {
6
6
  "lint": "eslint 'src/**/*.js' 'src/**/*.ts' --fix",
@@ -52,6 +52,57 @@ function debug(...args) {
52
52
  }
53
53
  }
54
54
 
55
+ /**
56
+ * Detect if we're running inside a Docker container.
57
+ *
58
+ * Checks the SKYRAMP_IN_DOCKER environment variable
59
+ *
60
+ * @returns {boolean} True if running in Docker, false otherwise
61
+ */
62
+ function isRunningInDocker() {
63
+ const envValue = (process.env.SKYRAMP_IN_DOCKER || '').toLowerCase();
64
+ return envValue === 'true' || envValue === '1' || envValue === 'yes';
65
+ }
66
+
67
+ /**
68
+ * Transform localhost URLs to host.docker.internal when running in Docker.
69
+ *
70
+ * This helper function automatically detects if we're running inside a Docker
71
+ * container and transforms localhost URLs to use host.docker.internal, which
72
+ * allows containers to access services running on the host machine.
73
+ *
74
+ * @param {string} url - The URL to potentially transform
75
+ * @returns {string} The transformed URL if in Docker and URL contains localhost, otherwise the original URL
76
+ */
77
+ function transformUrlForDocker(url) {
78
+ if (!url) {
79
+ return url;
80
+ }
81
+
82
+ // Auto-detect if we're running in Docker
83
+ if (!isRunningInDocker()) {
84
+ return url;
85
+ }
86
+
87
+ // Use proper URL parsing to only replace the hostname component
88
+ try {
89
+ const urlObj = new URL(url);
90
+ const hostname = urlObj.hostname;
91
+
92
+ // Only transform if hostname is exactly 'localhost' or '127.0.0.1'
93
+ if (hostname === 'localhost' || hostname === '127.0.0.1') {
94
+ urlObj.hostname = 'host.docker.internal';
95
+ const transformed = urlObj.toString();
96
+ debug(`Transformed URL: ${url} -> ${transformed}`);
97
+ return transformed;
98
+ }
99
+ } catch (error) {
100
+ debug(`Failed to parse URL: ${url}, returning original`);
101
+ }
102
+
103
+ return url;
104
+ }
105
+
55
106
  function shouldAttemptImprovement(errorMessage, errorName) {
56
107
  const improvementKeywords = [
57
108
  "timeout",
@@ -272,6 +323,13 @@ class SkyrampPlaywrightLocator {
272
323
  newMsg += this.generateLLMErrors();
273
324
  }
274
325
 
326
+ // Ensure error is an Error object, not a string
327
+ if (typeof error === 'string') {
328
+ error = new Error(error);
329
+ } else if (!(error instanceof Error)) {
330
+ error = new Error(String(error));
331
+ }
332
+
275
333
  error.message = error.message + "\n" + newMsg
276
334
 
277
335
  return error
@@ -279,7 +337,7 @@ class SkyrampPlaywrightLocator {
279
337
 
280
338
  hydrationErrorMsg = "Potentially a hydration issue. Please add enough waitForTimeout()"
281
339
 
282
- newPrevHyrdationErrorMsg() {
340
+ newPrevHydrationErrorMsg() {
283
341
  return `Cannot find locator ${this._locator} and likely a hydration issue on ${this._previousLocator._locator}.\n` +
284
342
  `Please add enough waitForTimeout() on ${this._previoousLocator._locator}`;
285
343
  }
@@ -765,7 +823,8 @@ class SkyrampPlaywrightPage {
765
823
  }
766
824
 
767
825
  async goto(url, options) {
768
- const result = await this._page.goto(url, options);
826
+ const transformedUrl = transformUrlForDocker(url);
827
+ const result = await this._page.goto(transformedUrl, options);
769
828
  const content = await this._page.content();
770
829
  if (hasJavascriptWrapper(content)) {
771
830
  debug(`javascript download detected when visiting ${this._page.url()}`);