@lunora/browser 1.0.0-alpha.3 → 1.0.0-alpha.4
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/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createBrowser } from './packem_shared/createBrowser-
|
|
1
|
+
export { createBrowser } from './packem_shared/createBrowser-BaV8oQ-4.mjs';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { LunoraError } from '@lunora/errors';
|
|
2
|
+
|
|
1
3
|
const DEFAULT_TIMEOUT_MS = 3e4;
|
|
2
4
|
const MAX_TIMEOUT_MS = 12e4;
|
|
3
5
|
const MAX_VIEWPORT_WIDTH = 3840;
|
|
@@ -109,7 +111,8 @@ const assertResolvedHostIsPublic = async (target, timeoutMs = DOH_TIMEOUT_MS) =>
|
|
|
109
111
|
}
|
|
110
112
|
for (const answer of [...aRecords ?? [], ...aaaaRecords ?? []]) {
|
|
111
113
|
if ((answer.type === DNS_TYPE_A || answer.type === DNS_TYPE_AAAA) && isPrivateResolvedIp(answer.data, answer.type)) {
|
|
112
|
-
throw new
|
|
114
|
+
throw new LunoraError(
|
|
115
|
+
"FORBIDDEN",
|
|
113
116
|
`@lunora/browser: url host "${host}" resolves to a private/internal address (${answer.data}); refusing to navigate (DNS-rebinding guard)`
|
|
114
117
|
);
|
|
115
118
|
}
|
|
@@ -126,28 +129,29 @@ const isPrivateTarget = (parsed) => {
|
|
|
126
129
|
};
|
|
127
130
|
const validateUrl = (url, allowPrivateTargets, allowedHosts) => {
|
|
128
131
|
if (typeof url !== "string" || url.length === 0) {
|
|
129
|
-
throw new
|
|
132
|
+
throw new TypeError("@lunora/browser: url must be a non-empty string");
|
|
130
133
|
}
|
|
131
134
|
let parsed;
|
|
132
135
|
try {
|
|
133
136
|
parsed = new URL(url);
|
|
134
137
|
} catch {
|
|
135
|
-
throw new
|
|
138
|
+
throw new TypeError(`@lunora/browser: url must be an absolute http(s) URL (got "${url}")`);
|
|
136
139
|
}
|
|
137
140
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
138
|
-
throw new
|
|
141
|
+
throw new TypeError(`@lunora/browser: url protocol must be http(s) (got "${parsed.protocol}")`);
|
|
139
142
|
}
|
|
140
143
|
if (parsed.username !== "" || parsed.password !== "") {
|
|
141
|
-
throw new
|
|
144
|
+
throw new LunoraError("INTERNAL", "@lunora/browser: url must not embed credentials (strip the `user:pass@` userinfo)");
|
|
142
145
|
}
|
|
143
146
|
if (allowedHosts && allowedHosts.length > 0) {
|
|
144
147
|
const host = normalizeHost(parsed.hostname);
|
|
145
148
|
if (!allowedHosts.some((entry) => normalizeHost(entry) === host)) {
|
|
146
|
-
throw new
|
|
149
|
+
throw new LunoraError("FORBIDDEN", `@lunora/browser: url host "${parsed.hostname}" is not in the configured allowedHosts allowlist`);
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
152
|
if (!allowPrivateTargets && isPrivateTarget(parsed)) {
|
|
150
|
-
throw new
|
|
153
|
+
throw new LunoraError(
|
|
154
|
+
"INTERNAL",
|
|
151
155
|
`@lunora/browser: url host "${parsed.hostname}" is a private/internal address; pass createBrowser({ …, allowPrivateTargets: true }) to allow it`
|
|
152
156
|
);
|
|
153
157
|
}
|
|
@@ -172,11 +176,12 @@ const resolveTimeout = (callTimeout, factoryTimeout) => {
|
|
|
172
176
|
};
|
|
173
177
|
const createBrowser = (options) => {
|
|
174
178
|
if (!options.binding) {
|
|
175
|
-
throw new
|
|
179
|
+
throw new TypeError("@lunora/browser: `binding` is required (env.BROWSER)");
|
|
176
180
|
}
|
|
177
181
|
const getLaunch = () => {
|
|
178
182
|
if (!options.launch) {
|
|
179
|
-
throw new
|
|
183
|
+
throw new LunoraError(
|
|
184
|
+
"INTERNAL",
|
|
180
185
|
'@lunora/browser: `launch` is not available — install the `@cloudflare/playwright` peer dependency. The generated worker wires it for you; outside codegen pass it via createBrowser({ binding, launch }) (import { launch } from "@cloudflare/playwright").'
|
|
181
186
|
);
|
|
182
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/browser",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
4
|
"description": "Cloudflare Browser Rendering for Lunora: ctx.browser screenshots, PDF, and scraping in actions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser-rendering",
|
|
@@ -45,6 +45,9 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@lunora/errors": "1.0.0-alpha.1"
|
|
50
|
+
},
|
|
48
51
|
"peerDependencies": {
|
|
49
52
|
"@cloudflare/playwright": ">=1.0.0"
|
|
50
53
|
},
|