@skyramp/skyramp 1.2.40 → 1.3.0
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
|
@@ -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",
|
|
@@ -772,7 +823,8 @@ class SkyrampPlaywrightPage {
|
|
|
772
823
|
}
|
|
773
824
|
|
|
774
825
|
async goto(url, options) {
|
|
775
|
-
const
|
|
826
|
+
const transformedUrl = transformUrlForDocker(url);
|
|
827
|
+
const result = await this._page.goto(transformedUrl, options);
|
|
776
828
|
const content = await this._page.content();
|
|
777
829
|
if (hasJavascriptWrapper(content)) {
|
|
778
830
|
debug(`javascript download detected when visiting ${this._page.url()}`);
|