webcake-landing-mcp 1.16.1 → 1.17.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/dist/auth/login.js +3 -2
- package/dist/auth/oauth-server.js +21 -18
- package/dist/changelog.json +14 -14
- package/dist/http.js +13 -7
- package/dist/persistence/config.js +6 -0
- package/dist/persistence/ingest/browser-capture.js +134 -18
- package/dist/persistence/postgres.js +3 -0
- package/dist/persistence/webcake-client.js +7 -4
- package/dist/smoke.js +4 -0
- package/dist/tools/clone.js +1 -1
- package/package.json +1 -1
package/dist/auth/login.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 1. open a loopback server on 127.0.0.1:<port>,
|
|
7
7
|
* 2. open the browser to the Webcake "connect" URL with redirect_uri=<loopback>,
|
|
8
8
|
* 3. the user is already logged in to Webcake, so Webcake reads their `jwt`
|
|
9
|
-
* cookie server-side and 302s back to the loopback with ?token=<jwt
|
|
9
|
+
* cookie server-side and 302s back to the loopback with ?token=<jwt>[&wsid=<lwsid>],
|
|
10
10
|
* 4. we save it to the credentials file (persistence/config.ts#saveSavedConfig),
|
|
11
11
|
* which the stdio/http server then reads automatically.
|
|
12
12
|
*
|
|
@@ -159,7 +159,7 @@ export function parseCallback(reqUrl, expectedState) {
|
|
|
159
159
|
return { ok: false, status: 400, reason: "no token in the callback — re-run the command" };
|
|
160
160
|
if (url.searchParams.get("state") !== expectedState)
|
|
161
161
|
return { ok: false, status: 400, reason: "state mismatch (login link truncated or expired) — re-run the command" };
|
|
162
|
-
return { ok: true, token };
|
|
162
|
+
return { ok: true, token, sessionId: url.searchParams.get("wsid") || url.searchParams.get("session_id") || undefined };
|
|
163
163
|
}
|
|
164
164
|
export async function runLogin(argv) {
|
|
165
165
|
const opts = parseArgs(argv);
|
|
@@ -193,6 +193,7 @@ export async function runLogin(argv) {
|
|
|
193
193
|
try {
|
|
194
194
|
path = saveSavedConfig({
|
|
195
195
|
jwt: cb.token,
|
|
196
|
+
sessionId: cb.sessionId, // undefined drops a stale one from a previous login
|
|
196
197
|
base: stripTrailingSlash(apiBase),
|
|
197
198
|
appBase: stripTrailingSlash(appBase),
|
|
198
199
|
...(opts.orgId ? { orgId: opts.orgId } : {}),
|
|
@@ -232,11 +232,11 @@ class PgStore {
|
|
|
232
232
|
};
|
|
233
233
|
}
|
|
234
234
|
async putCode(code, c) {
|
|
235
|
-
await this.pool.query(`INSERT INTO oauth_codes (code, client_id, redirect_uri, code_challenge, scope, ljwt, expires_at)
|
|
236
|
-
VALUES ($1,$2,$3,$4,$5,$6,$7)`, [code, c.client_id, c.redirect_uri, c.code_challenge, c.scope ?? null, c.ljwt, c.expiresAt]);
|
|
235
|
+
await this.pool.query(`INSERT INTO oauth_codes (code, client_id, redirect_uri, code_challenge, scope, ljwt, wsid, expires_at)
|
|
236
|
+
VALUES ($1,$2,$3,$4,$5,$6,$7,$8)`, [code, c.client_id, c.redirect_uri, c.code_challenge, c.scope ?? null, c.ljwt, c.wsid, c.expiresAt]);
|
|
237
237
|
}
|
|
238
238
|
async takeCode(code) {
|
|
239
|
-
const { rows } = await this.pool.query(`DELETE FROM oauth_codes WHERE code=$1 RETURNING client_id, redirect_uri, code_challenge, scope, ljwt, expires_at`, [code]);
|
|
239
|
+
const { rows } = await this.pool.query(`DELETE FROM oauth_codes WHERE code=$1 RETURNING client_id, redirect_uri, code_challenge, scope, ljwt, wsid, expires_at`, [code]);
|
|
240
240
|
const r = rows[0];
|
|
241
241
|
if (!r || Number(r.expires_at) < now())
|
|
242
242
|
return undefined;
|
|
@@ -246,14 +246,15 @@ class PgStore {
|
|
|
246
246
|
code_challenge: r.code_challenge,
|
|
247
247
|
scope: r.scope ?? undefined,
|
|
248
248
|
ljwt: r.ljwt,
|
|
249
|
+
wsid: r.wsid ?? "",
|
|
249
250
|
expiresAt: Number(r.expires_at),
|
|
250
251
|
};
|
|
251
252
|
}
|
|
252
253
|
async putAccess(t, a) {
|
|
253
|
-
await this.pool.query(`INSERT INTO oauth_access_tokens (token, ljwt, scope, expires_at) VALUES ($1,$2,$3,$4)`, [t, a.ljwt, a.scope ?? null, a.expiresAt]);
|
|
254
|
+
await this.pool.query(`INSERT INTO oauth_access_tokens (token, ljwt, wsid, scope, expires_at) VALUES ($1,$2,$3,$4,$5)`, [t, a.ljwt, a.wsid, a.scope ?? null, a.expiresAt]);
|
|
254
255
|
}
|
|
255
256
|
async getAccess(t) {
|
|
256
|
-
const { rows } = await this.pool.query(`SELECT ljwt, scope, expires_at FROM oauth_access_tokens WHERE token=$1`, [t]);
|
|
257
|
+
const { rows } = await this.pool.query(`SELECT ljwt, wsid, scope, expires_at FROM oauth_access_tokens WHERE token=$1`, [t]);
|
|
257
258
|
const r = rows[0];
|
|
258
259
|
if (!r)
|
|
259
260
|
return undefined;
|
|
@@ -261,18 +262,19 @@ class PgStore {
|
|
|
261
262
|
await this.pool.query(`DELETE FROM oauth_access_tokens WHERE token=$1`, [t]);
|
|
262
263
|
return undefined;
|
|
263
264
|
}
|
|
264
|
-
return { ljwt: r.ljwt, scope: r.scope ?? undefined, expiresAt: Number(r.expires_at) };
|
|
265
|
+
return { ljwt: r.ljwt, wsid: r.wsid ?? "", scope: r.scope ?? undefined, expiresAt: Number(r.expires_at) };
|
|
265
266
|
}
|
|
266
267
|
async putRefresh(t, r) {
|
|
267
|
-
await this.pool.query(`INSERT INTO oauth_refresh_tokens (token, ljwt, client_id, scope, expires_at) VALUES ($1,$2,$3,$4,$5)`, [t, r.ljwt, r.client_id, r.scope ?? null, r.expiresAt]);
|
|
268
|
+
await this.pool.query(`INSERT INTO oauth_refresh_tokens (token, ljwt, wsid, client_id, scope, expires_at) VALUES ($1,$2,$3,$4,$5,$6)`, [t, r.ljwt, r.wsid, r.client_id, r.scope ?? null, r.expiresAt]);
|
|
268
269
|
}
|
|
269
270
|
async takeRefresh(t) {
|
|
270
|
-
const { rows } = await this.pool.query(`DELETE FROM oauth_refresh_tokens WHERE token=$1 RETURNING ljwt, client_id, scope, expires_at`, [t]);
|
|
271
|
+
const { rows } = await this.pool.query(`DELETE FROM oauth_refresh_tokens WHERE token=$1 RETURNING ljwt, wsid, client_id, scope, expires_at`, [t]);
|
|
271
272
|
const r = rows[0];
|
|
272
273
|
if (!r || Number(r.expires_at) < now())
|
|
273
274
|
return undefined;
|
|
274
275
|
return {
|
|
275
276
|
ljwt: r.ljwt,
|
|
277
|
+
wsid: r.wsid ?? "",
|
|
276
278
|
client_id: r.client_id,
|
|
277
279
|
scope: r.scope ?? undefined,
|
|
278
280
|
expiresAt: Number(r.expires_at),
|
|
@@ -399,12 +401,12 @@ export async function startAuthorize(p) {
|
|
|
399
401
|
return { ok: true, internalState };
|
|
400
402
|
}
|
|
401
403
|
/**
|
|
402
|
-
* The login page (/mcp-connect) bounced back with the user's `ljwt`
|
|
403
|
-
* `internalState`. Mint a one-time authorization code bound to that ljwt + the
|
|
404
|
+
* The login page (/mcp-connect) bounced back with the user's `ljwt` (+ optional
|
|
405
|
+
* `wsid`) and our `internalState`. Mint a one-time authorization code bound to that ljwt + the
|
|
404
406
|
* parked PKCE challenge, and return where to redirect the user (the client's
|
|
405
407
|
* redirect_uri with ?code=&state=).
|
|
406
408
|
*/
|
|
407
|
-
export async function completeAuthorize(internalState, ljwt) {
|
|
409
|
+
export async function completeAuthorize(internalState, ljwt, wsid) {
|
|
408
410
|
const store = await getStore();
|
|
409
411
|
const p = internalState ? await store.takePending(internalState) : undefined;
|
|
410
412
|
if (!p) {
|
|
@@ -420,15 +422,16 @@ export async function completeAuthorize(internalState, ljwt) {
|
|
|
420
422
|
code_challenge: p.code_challenge,
|
|
421
423
|
scope: p.scope,
|
|
422
424
|
ljwt,
|
|
425
|
+
wsid: wsid ?? "",
|
|
423
426
|
expiresAt: now() + CODE_TTL,
|
|
424
427
|
});
|
|
425
428
|
return { ok: true, redirectUri: p.redirect_uri, code, state: p.state };
|
|
426
429
|
}
|
|
427
|
-
async function issueTokens(store, ljwt, client_id, scope) {
|
|
430
|
+
async function issueTokens(store, ljwt, wsid, client_id, scope) {
|
|
428
431
|
const access = token(32);
|
|
429
432
|
const refresh = token(32);
|
|
430
|
-
await store.putAccess(access, { ljwt, scope, expiresAt: now() + ACCESS_TTL });
|
|
431
|
-
await store.putRefresh(refresh, { ljwt, client_id, scope, expiresAt: now() + REFRESH_TTL });
|
|
433
|
+
await store.putAccess(access, { ljwt, wsid, scope, expiresAt: now() + ACCESS_TTL });
|
|
434
|
+
await store.putRefresh(refresh, { ljwt, wsid, client_id, scope, expiresAt: now() + REFRESH_TTL });
|
|
432
435
|
return { access_token: access, token_type: "Bearer", expires_in: Math.floor(ACCESS_TTL / 1000), refresh_token: refresh, scope };
|
|
433
436
|
}
|
|
434
437
|
export async function exchangeToken(p) {
|
|
@@ -447,7 +450,7 @@ export async function exchangeToken(p) {
|
|
|
447
450
|
if (!p.code_verifier || !verifyPkce(p.code_verifier, c.code_challenge)) {
|
|
448
451
|
return { ok: false, status: 400, error: "invalid_grant", error_description: "PKCE verification failed." };
|
|
449
452
|
}
|
|
450
|
-
return { ok: true, body: await issueTokens(store, c.ljwt, c.client_id, c.scope) };
|
|
453
|
+
return { ok: true, body: await issueTokens(store, c.ljwt, c.wsid, c.client_id, c.scope) };
|
|
451
454
|
}
|
|
452
455
|
if (p.grant_type === "refresh_token") {
|
|
453
456
|
const r = p.refresh_token ? await store.takeRefresh(p.refresh_token) : undefined; // rotate
|
|
@@ -457,17 +460,17 @@ export async function exchangeToken(p) {
|
|
|
457
460
|
if (await isDeadJwt(r.ljwt)) {
|
|
458
461
|
return { ok: false, status: 400, error: "invalid_grant", error_description: "Webcake session expired — sign in again (Connect)." };
|
|
459
462
|
}
|
|
460
|
-
return { ok: true, body: await issueTokens(store, r.ljwt, r.client_id, r.scope) };
|
|
463
|
+
return { ok: true, body: await issueTokens(store, r.ljwt, r.wsid, r.client_id, r.scope) };
|
|
461
464
|
}
|
|
462
465
|
return { ok: false, status: 400, error: "unsupported_grant_type", error_description: "grant_type must be authorization_code or refresh_token." };
|
|
463
466
|
}
|
|
464
467
|
// ---- Resource-server side: resolve a Bearer access token to its ljwt -------
|
|
465
|
-
/** Returns the user's ljwt for a valid, unexpired access token, else undefined. */
|
|
468
|
+
/** Returns the user's { ljwt, wsid } for a valid, unexpired access token, else undefined. */
|
|
466
469
|
export async function resolveAccessToken(accessToken) {
|
|
467
470
|
if (!accessToken)
|
|
468
471
|
return undefined;
|
|
469
472
|
const a = await (await getStore()).getAccess(accessToken);
|
|
470
|
-
return a && !isDeadLocally(a.ljwt) ? a.ljwt : undefined;
|
|
473
|
+
return a && !isDeadLocally(a.ljwt) ? { ljwt: a.ljwt, wsid: a.wsid } : undefined;
|
|
471
474
|
}
|
|
472
475
|
/** Revoke an access or refresh token (best-effort; for /revoke). */
|
|
473
476
|
export async function revokeToken(t) {
|
package/dist/changelog.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "1.17.0",
|
|
4
|
+
"d": "28/11/2026",
|
|
5
|
+
"type": "Fixed",
|
|
6
|
+
"en": "clone_page and ingest_html/ingest_url with intent:'clone' now dismiss cookie/consent/newsletter banners, promo modals and chat widgets (clicking…",
|
|
7
|
+
"vi": "clone_page và ingest_html/ingest_url với intent:'clone' nay bỏ các lớp cookie/consent/newsletter, modal quảng cáo và widget chat (bấm nút chấp…"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"v": "1.16.2",
|
|
11
|
+
"d": "28/11/2026",
|
|
12
|
+
"type": "Fixed",
|
|
13
|
+
"en": "login and the OAuth connect flow now also capture the landing session id (wsid, the SPA's lwsid cookie) alongside the JWT and persistence calls send…",
|
|
14
|
+
"vi": "login và luồng OAuth connect nay cũng lấy thêm session id landing (wsid, tức cookie lwsid của SPA) cùng với JWT, và các lượt gọi persistence gửi nó…"
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"v": "1.16.1",
|
|
4
18
|
"d": "25/11/2026",
|
|
@@ -26,19 +40,5 @@
|
|
|
26
40
|
"type": "Added",
|
|
27
41
|
"en": "ingest_html and ingest_url with intent:'clone' now measure a page that is not an absolute-canvas export in a real browser, the same way clone_page…",
|
|
28
42
|
"vi": "ingest_html và ingest_url với intent:'clone' nay đo trang không phải export dạng canvas tuyệt đối bằng một trình duyệt thật, giống cách clone_page…"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"v": "1.13.7",
|
|
32
|
-
"d": "22/11/2026",
|
|
33
|
-
"type": "Fixed",
|
|
34
|
-
"en": "install now writes the Claude Desktop config to every location Claude may read on Windows (Store/MSIX package containers, Claude-Data,…",
|
|
35
|
-
"vi": "install nay ghi config Claude Desktop vào mọi vị trí Claude có thể đọc trên Windows (container gói Store/MSIX, Claude-Data, %APPDATA%\\Claude) thay…"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"v": "1.13.6",
|
|
39
|
-
"d": "20/11/2026",
|
|
40
|
-
"type": "Fixed",
|
|
41
|
-
"en": "update_page/patch_page no longer compute a sections-only diff against a page that has two elements sharing the same id (something the Webcake editor…",
|
|
42
|
-
"vi": "update_page/patch_page nay không còn tính diff theo từng section với một trang có hai element dùng chung id (điều mà chính editor Webcake vẫn cho…"
|
|
43
43
|
}
|
|
44
44
|
]
|
package/dist/http.js
CHANGED
|
@@ -109,13 +109,15 @@ async function readBody(req) {
|
|
|
109
109
|
// require HTTPS, and disable query-string logging on your reverse proxy.
|
|
110
110
|
const QUERY_AUTH = {
|
|
111
111
|
jwt: "x-webcake-jwt",
|
|
112
|
+
wsid: "x-webcake-session-id",
|
|
113
|
+
session_id: "x-webcake-session-id",
|
|
112
114
|
env: "x-webcake-env",
|
|
113
115
|
api_base: "x-webcake-api-base",
|
|
114
116
|
org_id: "x-webcake-org-id",
|
|
115
117
|
app_base: "x-webcake-app-base",
|
|
116
118
|
builder_base: "x-webcake-builder-base",
|
|
117
119
|
};
|
|
118
|
-
function applyQueryAuth(req) {
|
|
120
|
+
export function applyQueryAuth(req) {
|
|
119
121
|
const q = (req.url ?? "").indexOf("?");
|
|
120
122
|
if (q === -1)
|
|
121
123
|
return;
|
|
@@ -252,7 +254,7 @@ async function handleOAuth(req, res, path) {
|
|
|
252
254
|
}
|
|
253
255
|
return htmlError(res, 400, result.error_description), true;
|
|
254
256
|
}
|
|
255
|
-
// Send the user to the SPA login; it returns here with ?token=<ljwt
|
|
257
|
+
// Send the user to the SPA login; it returns here with ?token=<ljwt>[&wsid=<lwsid>]&state=<internalState>.
|
|
256
258
|
const callback = `${issuer}${OAUTH_CALLBACK}`;
|
|
257
259
|
const loginUrl = buildConnectUrl(connectPageUrl(), callback, result.internalState);
|
|
258
260
|
res.writeHead(302, { location: loginUrl });
|
|
@@ -261,7 +263,7 @@ async function handleOAuth(req, res, path) {
|
|
|
261
263
|
// ---- Login callback: the SPA handed back the user's ljwt → mint a code ----
|
|
262
264
|
if (req.method === "GET" && path === OAUTH_CALLBACK) {
|
|
263
265
|
const sp = new URL(req.url ?? "/", "http://x").searchParams;
|
|
264
|
-
const done = await completeAuthorize(sp.get("state"), sp.get("token"));
|
|
266
|
+
const done = await completeAuthorize(sp.get("state"), sp.get("token"), sp.get("wsid") || sp.get("session_id"));
|
|
265
267
|
if (!done.ok)
|
|
266
268
|
return htmlError(res, 400, done.error_description), true;
|
|
267
269
|
const r = new URL(done.redirectUri);
|
|
@@ -478,10 +480,14 @@ export async function startHttpServer(port) {
|
|
|
478
480
|
// ?jwt= / x-webcake-jwt: a Bearer from our OAuth flow is what the last Connect issued,
|
|
479
481
|
// so it's the renewed credential when the URL still carries an old, expired JWT.
|
|
480
482
|
const bearer = bearerFrom(req);
|
|
481
|
-
const
|
|
482
|
-
if (
|
|
483
|
-
req.headers["x-webcake-jwt"] =
|
|
484
|
-
req.rawHeaders.push("x-webcake-jwt",
|
|
483
|
+
const oauthCred = await resolveAccessToken(bearer);
|
|
484
|
+
if (oauthCred) {
|
|
485
|
+
req.headers["x-webcake-jwt"] = oauthCred.ljwt;
|
|
486
|
+
req.rawHeaders.push("x-webcake-jwt", oauthCred.ljwt);
|
|
487
|
+
if (oauthCred.wsid) {
|
|
488
|
+
req.headers["x-webcake-session-id"] = oauthCred.wsid;
|
|
489
|
+
req.rawHeaders.push("x-webcake-session-id", oauthCred.wsid);
|
|
490
|
+
}
|
|
485
491
|
}
|
|
486
492
|
// Enforcement: no credential, or an expired/rejected Webcake JWT, gets a 401 +
|
|
487
493
|
// WWW-Authenticate so Claude/ChatGPT (re)open the Connect page by themselves. In
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* explicit WEBCAKE_API_BASE / WEBCAKE_APP_BASE still wins over it.
|
|
18
18
|
* WEBCAKE_API_BASE e.g. http://localhost:5800 (required to call the backend)
|
|
19
19
|
* WEBCAKE_JWT the account JWT (required to call the backend)
|
|
20
|
+
* WEBCAKE_SESSION_ID optional landing session id (`lwsid`), sent as `x-session-id`
|
|
20
21
|
* WEBCAKE_ORG_ID optional default organization id for create_page
|
|
21
22
|
* WEBCAKE_APP_BASE optional SPA base (used for the login connect page)
|
|
22
23
|
* WEBCAKE_BUILDER_BASE optional builder host for the editor URLs in the result
|
|
@@ -91,6 +92,8 @@ export function readConfig(overrides = {}) {
|
|
|
91
92
|
const envJwt = process.env.WEBCAKE_JWT;
|
|
92
93
|
const renewed = !!envJwt && jwtExpired(envJwt) && !!saved.jwt && !jwtExpired(saved.jwt);
|
|
93
94
|
const jwt = overrides.jwt ?? (renewed ? saved.jwt : envJwt) ?? saved.jwt;
|
|
95
|
+
// The session id belongs to the JWT it was issued with — take it from the same source.
|
|
96
|
+
const sessionId = overrides.jwt ? overrides.sessionId : envJwt && !renewed ? process.env.WEBCAKE_SESSION_ID : saved.sessionId;
|
|
94
97
|
const missing = [];
|
|
95
98
|
if (!base)
|
|
96
99
|
missing.push("WEBCAKE_API_BASE");
|
|
@@ -128,6 +131,7 @@ export function readConfig(overrides = {}) {
|
|
|
128
131
|
config: {
|
|
129
132
|
base: cleanBase,
|
|
130
133
|
jwt: jwt,
|
|
134
|
+
sessionId: sessionId || undefined,
|
|
131
135
|
orgId: overrides.orgId ?? process.env.WEBCAKE_ORG_ID ?? saved.orgId,
|
|
132
136
|
appBase: stripTrailingSlash(overrides.appBase ?? process.env.WEBCAKE_APP_BASE ?? preset?.appBase ?? saved.appBase),
|
|
133
137
|
builderBase,
|
|
@@ -145,6 +149,7 @@ function header(headers, name) {
|
|
|
145
149
|
* Build request-scoped config overrides from HTTP headers. Lets a remote client
|
|
146
150
|
* send its own credentials per request instead of a server-wide env token:
|
|
147
151
|
* x-webcake-jwt the account JWT (or `Authorization: Bearer <jwt>`)
|
|
152
|
+
* x-webcake-session-id landing session id (`lwsid`), forwarded as `x-session-id`
|
|
148
153
|
* x-webcake-org-id organization id
|
|
149
154
|
* x-webcake-env named environment (local|staging|prod) for the base URLs
|
|
150
155
|
* x-webcake-api-base backend base URL (overrides the env preset)
|
|
@@ -159,6 +164,7 @@ export function configFromHeaders(headers) {
|
|
|
159
164
|
return {
|
|
160
165
|
base: header(headers, "x-webcake-api-base"),
|
|
161
166
|
jwt: header(headers, "x-webcake-jwt") ?? bearer,
|
|
167
|
+
sessionId: header(headers, "x-webcake-session-id"),
|
|
162
168
|
orgId: header(headers, "x-webcake-org-id"),
|
|
163
169
|
appBase: header(headers, "x-webcake-app-base"),
|
|
164
170
|
builderBase: header(headers, "x-webcake-builder-base"),
|
|
@@ -52,9 +52,12 @@ function captureInPage(opt) {
|
|
|
52
52
|
out["font-weight"] = s.fontWeight;
|
|
53
53
|
if (s.fontStyle === "italic")
|
|
54
54
|
out["font-style"] = "italic";
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
// the family + its generic fallback ('pangea', sans-serif): a self-hosted font that has not loaded yet
|
|
56
|
+
// (re-hosted on save) must not fall back to the browser's serif
|
|
57
|
+
const stack = s.fontFamily.split(",").map((f) => f.trim().replace(/^['"]|['"]$/g, ""));
|
|
58
|
+
const generic = stack.find((f) => /^(sans-serif|serif|monospace|cursive|fantasy|system-ui)$/.test(f)) ?? "sans-serif";
|
|
59
|
+
if (stack[0])
|
|
60
|
+
out["font-family"] = stack[0] === generic ? generic : `'${stack[0]}', ${generic}`;
|
|
58
61
|
// landing lineHeight is a multiplier of the font size
|
|
59
62
|
if (s.lineHeight !== "normal" && fs)
|
|
60
63
|
out["line-height"] = String(Math.round((parseFloat(s.lineHeight) / fs) * 100) / 100);
|
|
@@ -142,7 +145,9 @@ function captureInPage(opt) {
|
|
|
142
145
|
const inlineOnly = (el) => Array.from(el.children).every((c) => {
|
|
143
146
|
const d = cs(c).display;
|
|
144
147
|
return (d.startsWith("inline") && !["IMG", "SVG", "svg", "BUTTON", "INPUT", "SELECT", "TEXTAREA", "VIDEO", "IFRAME"].includes(c.tagName)) || d === "none" || c.tagName === "BR" || icon(c);
|
|
145
|
-
})
|
|
148
|
+
}) &&
|
|
149
|
+
// …and nothing inside is laid out on its own (a badge absolutely placed over a menu link): that is drawn separately
|
|
150
|
+
!Array.from(el.querySelectorAll("*")).some((d) => ["absolute", "fixed"].includes(cs(d).position) && shown(d));
|
|
146
151
|
/** the text a visitor sees: skips screen-reader-only / hidden descendants (innerText keeps them). */
|
|
147
152
|
const visibleText = (el) => {
|
|
148
153
|
let out = "";
|
|
@@ -291,8 +296,8 @@ function captureInPage(opt) {
|
|
|
291
296
|
// order → POPUP1…; the buttons/links that open them become open_popup events.
|
|
292
297
|
const POPUP_SEL = 'dialog, [role="dialog"], [aria-modal="true"], .modal, .popup, [class*="popup"], [class*="modal"], [id*="popup"], [id*="modal"]';
|
|
293
298
|
const popupEls = Array.from(document.querySelectorAll(POPUP_SEL)).filter((c, i, all) => {
|
|
294
|
-
if (all.some((o) => o !== c && o.contains(c)))
|
|
295
|
-
return false; // outermost only
|
|
299
|
+
if (all.some((o) => o !== c && o.contains(c)) || c.closest("[data-wc-dismissed]"))
|
|
300
|
+
return false; // outermost only; no dismissed cookie bar / chat
|
|
296
301
|
const s = cs(c);
|
|
297
302
|
// a modal overlays the page (fixed / dialog); a hidden "popup-menu" dropdown sits in the flow
|
|
298
303
|
const overlay = c.tagName === "DIALOG" || s.position === "fixed" || c.getAttribute("role") === "dialog" || c.getAttribute("aria-modal") === "true" || c.classList.contains("modal");
|
|
@@ -364,12 +369,23 @@ function captureInPage(opt) {
|
|
|
364
369
|
const byTop = (a, b) => a.getBoundingClientRect().top - b.getBoundingClientRect().top;
|
|
365
370
|
// fixed / absolute layers (floating widgets, side TOCs, overlays) are not bands: each becomes a pinned
|
|
366
371
|
// group inside the section where it sits.
|
|
367
|
-
|
|
372
|
+
// A fixed bar across the top (the site header) IS a band — the section's native sticky — when the
|
|
373
|
+
// page keeps room for it (nothing with content starts under it); a fixed header laid over the hero stays a layer.
|
|
374
|
+
const contentful = (b) => !!b.innerText?.trim() || !!b.querySelector("img,svg,video,iframe,canvas,picture,input,select,textarea") || painted(cs(b));
|
|
375
|
+
const topBar = (c) => {
|
|
376
|
+
const r = c.getBoundingClientRect();
|
|
377
|
+
return cs(c).position === "fixed" && r.top <= 1 && r.width >= vw * 0.9 && r.height <= window.innerHeight * 0.4 &&
|
|
378
|
+
Array.from(root.children).every((o) => o === c || isOverlayRaw(o) || !shown(o) || !contentful(o) || o.getBoundingClientRect().top >= r.bottom - 4);
|
|
379
|
+
};
|
|
380
|
+
const isOverlayRaw = (c) => ["fixed", "absolute"].includes(cs(c).position);
|
|
381
|
+
const isOverlay = (c) => isOverlayRaw(c) && !(c.parentElement === root && topBar(c));
|
|
368
382
|
// A tall band made of full-width blocks stacked one under another (<main> wrapping every section)
|
|
369
|
-
// is split into those blocks, down to 3 levels.
|
|
383
|
+
// is split into those blocks, down to 3 levels; a lone wrapper inside it (<main><div>…) is looked through.
|
|
370
384
|
const flatten = (els, depth) => els.flatMap((b) => {
|
|
371
385
|
const r = b.getBoundingClientRect();
|
|
372
|
-
|
|
386
|
+
let kids = sizeable(b).filter((c) => !isOverlay(c)).sort(byTop);
|
|
387
|
+
for (let i = 0; i < 4 && kids.length === 1 && !realForm(kids[0]) && !slidesOf(kids[0]).length; i++)
|
|
388
|
+
kids = sizeable(kids[0]).filter((c) => !isOverlay(c)).sort(byTop);
|
|
373
389
|
const stacked = kids.length >= 2 && kids.every((c, i) => {
|
|
374
390
|
const q = c.getBoundingClientRect();
|
|
375
391
|
// stacked: each block starts below the middle of the previous one (angled / overlapping
|
|
@@ -381,7 +397,8 @@ function captureInPage(opt) {
|
|
|
381
397
|
});
|
|
382
398
|
const topLevel = sizeable(root).sort(byTop);
|
|
383
399
|
const overlayEls = topLevel.filter(isOverlay);
|
|
384
|
-
|
|
400
|
+
// an empty band (a spacer under a fixed header) adds no section: the band above spans its room
|
|
401
|
+
const bandEls = flatten(topLevel.filter((c) => !isOverlay(c)), 0).filter(contentful).sort(byTop);
|
|
385
402
|
// popups mode: show each hidden popup and measure its content box as its own band
|
|
386
403
|
const popupContents = [];
|
|
387
404
|
if (opt.popups) {
|
|
@@ -440,7 +457,12 @@ function captureInPage(opt) {
|
|
|
440
457
|
const span = spanOf(bands.indexOf(band));
|
|
441
458
|
const secTop = span.top;
|
|
442
459
|
const bs = cs(band);
|
|
443
|
-
|
|
460
|
+
// a transparent band shows the wrapper it was split from (<main class="bg-light">), else the page's background
|
|
461
|
+
let bgEl = band;
|
|
462
|
+
while (alpha(cs(bgEl).backgroundColor) === 0 && bgEl.parentElement && bgEl !== root)
|
|
463
|
+
bgEl = bgEl.parentElement;
|
|
464
|
+
const bgColor = cs(bgEl).backgroundColor;
|
|
465
|
+
const background = { "background-color": rgba(alpha(bgColor) > 0 ? bgColor : pageBg) };
|
|
444
466
|
if (bgUrl(bs))
|
|
445
467
|
background["background-image"] = bgUrl(bs);
|
|
446
468
|
else if (gradient(bs))
|
|
@@ -554,8 +576,15 @@ function captureInPage(opt) {
|
|
|
554
576
|
sink.push(raw);
|
|
555
577
|
};
|
|
556
578
|
const visit = (el, inForm) => {
|
|
557
|
-
if (SKIP.has(el.tagName) ||
|
|
579
|
+
if (SKIP.has(el.tagName) || count >= maxElements)
|
|
558
580
|
return;
|
|
581
|
+
if (!shown(el)) {
|
|
582
|
+
// a 0×0 wrapper that does not clip (an inline <a> around an absolute ticker item) still shows its children
|
|
583
|
+
const z = cs(el), zr = el.getBoundingClientRect();
|
|
584
|
+
if ((zr.width <= 2 || zr.height <= 2) && z.display !== "none" && z.visibility !== "hidden" && parseFloat(z.opacity) > 0.02 && z.overflowX === "visible" && z.overflowY === "visible")
|
|
585
|
+
Array.from(el.children).forEach((c) => visit(c, inForm));
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
559
588
|
const s = cs(el);
|
|
560
589
|
const tag = el.tagName;
|
|
561
590
|
const style = {};
|
|
@@ -727,8 +756,22 @@ function captureInPage(opt) {
|
|
|
727
756
|
}
|
|
728
757
|
if (inForm && (FIELD.has(tag) || tag === "BUTTON" || consumed.has(el)))
|
|
729
758
|
return; // already a form field
|
|
730
|
-
if (FIELD.has(tag))
|
|
731
|
-
|
|
759
|
+
if (FIELD.has(tag)) {
|
|
760
|
+
// a field outside a form cannot submit on a landing page: its look stays (a search box) — the box + its placeholder
|
|
761
|
+
if (painted(s)) {
|
|
762
|
+
paint(s, style);
|
|
763
|
+
push({ __el: el, key: keyOf(el) + "~bg", kind: "box", box: boxOf(el), style });
|
|
764
|
+
}
|
|
765
|
+
const hint = String(el.placeholder || (tag === "SELECT" ? el.selectedOptions?.[0]?.text : el.value) || "").trim();
|
|
766
|
+
if (hint && !["checkbox", "radio", "range", "color", "file", "hidden"].includes(el.type)) {
|
|
767
|
+
const st = {};
|
|
768
|
+
typo(s, st);
|
|
769
|
+
if (el.placeholder && !el.value)
|
|
770
|
+
st.color = getComputedStyle(el, "::placeholder").color;
|
|
771
|
+
push({ key: keyOf(el), kind: "paragraph", text: esc(hint), box: contentBox(el, s), style: st });
|
|
772
|
+
}
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
732
775
|
const text = visibleText(el);
|
|
733
776
|
const buttonish = (tag === "A" || tag === "BUTTON" || el.getAttribute("role") === "button") && painted(s) && text.length > 0 && text.length <= 60 && el.getBoundingClientRect().height <= 120;
|
|
734
777
|
if (buttonish) {
|
|
@@ -972,6 +1015,72 @@ function openCollapsibles() {
|
|
|
972
1015
|
mark(panel, t, open);
|
|
973
1016
|
});
|
|
974
1017
|
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Runs in the page BEFORE the measurement: what floats over the page that is not its design is taken away.
|
|
1020
|
+
* Consent / newsletter / promo layers are dismissed the way a visitor does (their accept / close control
|
|
1021
|
+
* clicked: Vietnamese + English texts, aria-labels); what still floats then — cookie bars, empty
|
|
1022
|
+
* full-screen dim backdrops, chat widgets — is hidden and left out (data-wc-dismissed), and a promo modal
|
|
1023
|
+
* left open is hidden too (the popup pass measures it as a landing popup). Only position:fixed layers are touched, never the site header
|
|
1024
|
+
* or anything in the flow.
|
|
1025
|
+
*/
|
|
1026
|
+
function dismissOverlays() {
|
|
1027
|
+
const vw = document.documentElement.clientWidth, vh = window.innerHeight;
|
|
1028
|
+
const CONSENT = /cookie|consent|gdpr|quyền riêng tư|privacy/i;
|
|
1029
|
+
const PROMO = /newsletter|subscribe|popup|modal|dialog|promo|đăng ký nhận/i;
|
|
1030
|
+
const CHAT = /chat|messenger|zalo|tawk|crisp|intercom|tidio|zopim|livechat|hubspot-messages|freshchat|drift|contact-fab|hỗ trợ|support/i;
|
|
1031
|
+
const CLOSE = /^(chấp nhận( tất cả)?|đồng ý( tất cả)?|tôi đồng ý|accept( all)?( cookies)?|allow( all)?( cookies)?|agree|i agree|got it|ok(ay)?|đã hiểu|đóng|close|dismiss|no,? thanks|không,? cảm ơn|bỏ qua|để sau|later|[×✕✖xX])$/i;
|
|
1032
|
+
const attrs = (el) => `${el.id || ""} ${typeof el.className === "string" ? el.className : ""} ${el.getAttribute("aria-label") || ""} ${el.getAttribute("role") || ""}`;
|
|
1033
|
+
const visible = (el) => {
|
|
1034
|
+
const r = el.getBoundingClientRect(), s = getComputedStyle(el);
|
|
1035
|
+
return r.width > 2 && r.height > 2 && s.display !== "none" && s.visibility !== "hidden" && parseFloat(s.opacity) > 0.02;
|
|
1036
|
+
};
|
|
1037
|
+
const header = (el) => el.matches("header, [role=banner]") || !!el.querySelector("nav, [role=navigation]");
|
|
1038
|
+
/** the outermost position:fixed ancestor-or-self (below <body>) */
|
|
1039
|
+
const layerOf = (el) => {
|
|
1040
|
+
let out = null;
|
|
1041
|
+
for (let n = el; n && n !== document.body; n = n.parentElement)
|
|
1042
|
+
if (getComputedStyle(n).position === "fixed")
|
|
1043
|
+
out = n;
|
|
1044
|
+
return out;
|
|
1045
|
+
};
|
|
1046
|
+
const kind = (el) => {
|
|
1047
|
+
const text = (el.innerText || "").trim();
|
|
1048
|
+
if (CONSENT.test(attrs(el)) || /cookie|consent|gdpr/i.test(text) || (CONSENT.test(text) && text.length < 800))
|
|
1049
|
+
return "consent";
|
|
1050
|
+
if (el.matches("dialog, [role=dialog], [aria-modal=true]") || PROMO.test(attrs(el)))
|
|
1051
|
+
return "promo";
|
|
1052
|
+
return "";
|
|
1053
|
+
};
|
|
1054
|
+
// 1. the visitor's click: accept / close inside a consent or promo layer (no navigation, no form submit)
|
|
1055
|
+
for (const b of Array.from(document.querySelectorAll("button, a, [role=button], input[type=button]"))) {
|
|
1056
|
+
const t = (b.innerText || b.value || b.getAttribute("aria-label") || b.getAttribute("title") || "").trim().replace(/\s+/g, " ");
|
|
1057
|
+
if (!CLOSE.test(t) || !visible(b) || (b.tagName === "A" && /^https?:|^\//.test(b.getAttribute("href") || "")) || (b.closest("form") && b.type !== "button"))
|
|
1058
|
+
continue;
|
|
1059
|
+
const layer = layerOf(b) || b.closest("dialog, [role=dialog], [aria-modal=true]");
|
|
1060
|
+
if (layer && !header(layer) && kind(layer)) {
|
|
1061
|
+
try {
|
|
1062
|
+
b.click();
|
|
1063
|
+
}
|
|
1064
|
+
catch { /* a handler that throws */ }
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
// 2. what still floats
|
|
1068
|
+
for (const el of Array.from(document.querySelectorAll("body *"))) {
|
|
1069
|
+
if (!el.isConnected || getComputedStyle(el).position !== "fixed" || layerOf(el) !== el || !visible(el) || header(el))
|
|
1070
|
+
continue;
|
|
1071
|
+
const r = el.getBoundingClientRect();
|
|
1072
|
+
const k = kind(el);
|
|
1073
|
+
const text = (el.innerText || "").trim();
|
|
1074
|
+
const backdrop = r.width >= vw * 0.9 && r.height >= vh * 0.9 && !text && !el.querySelector("img, svg, video, iframe, picture, canvas");
|
|
1075
|
+
const small = r.width * r.height < vw * vh * 0.15;
|
|
1076
|
+
const chat = small && (CHAT.test(attrs(el)) || Array.from(el.querySelectorAll("[id], [class], [aria-label], iframe")).some((d) => CHAT.test(attrs(d)) || CHAT.test(d.src || "")) || (text.length <= 24 && CHAT.test(text)));
|
|
1077
|
+
// hidden, not removed: a framework (React…) that still owns the node crashes when it is gone
|
|
1078
|
+
if (k === "consent" || backdrop || chat)
|
|
1079
|
+
el.setAttribute("data-wc-dismissed", "");
|
|
1080
|
+
if (k || backdrop || chat)
|
|
1081
|
+
el.style.setProperty("display", "none", "important");
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
975
1084
|
async function captureAt(target, width) {
|
|
976
1085
|
const r = await withContext(width, 1, async (ctx) => {
|
|
977
1086
|
// Every request the page makes (subresources, redirects, html-embedded urls) passes the same
|
|
@@ -989,6 +1098,9 @@ async function captureAt(target, width) {
|
|
|
989
1098
|
}
|
|
990
1099
|
else
|
|
991
1100
|
await page.setContent(withBase(target.html, target.baseUrl), { waitUntil: "networkidle", timeout: 30000 }).catch(() => undefined);
|
|
1101
|
+
await page.evaluate(dismissOverlays).catch(() => undefined);
|
|
1102
|
+
await page.waitForTimeout(300); // the dismissed layers' close animations
|
|
1103
|
+
await page.evaluate(dismissOverlays).catch(() => undefined);
|
|
992
1104
|
await page.evaluate(openCollapsibles).catch(() => undefined);
|
|
993
1105
|
// An app shell that scrolls inside a full-height box (body = one viewport, content in a
|
|
994
1106
|
// overflow:auto div): unlock it so the document is as tall as the page.
|
|
@@ -1019,6 +1131,8 @@ async function captureAt(target, width) {
|
|
|
1019
1131
|
window.scrollTo({ top: 0, behavior: "instant" });
|
|
1020
1132
|
});
|
|
1021
1133
|
await page.waitForTimeout(400);
|
|
1134
|
+
// a layer that only appeared while scrolling (a newsletter after N seconds / % scrolled)
|
|
1135
|
+
await page.evaluate(dismissOverlays).catch(() => undefined);
|
|
1022
1136
|
const main = await page.evaluate(captureInPage, { max: MAX_ELEMENTS, popups: false });
|
|
1023
1137
|
// second pass reveals the hidden popups (mutates the page: after the main capture)
|
|
1024
1138
|
const pop = await page.evaluate(captureInPage, { max: 200, popups: true }).catch(() => null);
|
|
@@ -1149,7 +1263,7 @@ export function mergeCaptures(desk, mob) {
|
|
|
1149
1263
|
// element is placed by its absolute page position; each desktop section gets a mobile FRAME — from its
|
|
1150
1264
|
// matched elements down to the next section's frame — and its mobile boxes are relative to that frame.
|
|
1151
1265
|
// Matching is by DOM path, else by what the element shows (text / picture / icon); a section that
|
|
1152
|
-
// barely matches hides nothing on mobile (scaled fallback) and gets no mobile-only additions.
|
|
1266
|
+
// barely matches (and is not the same band there) hides nothing on mobile (scaled fallback) and gets no mobile-only additions.
|
|
1153
1267
|
const sigOf = (e) => (e.text ? `t:${e.text.replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim().slice(0, 80)}` : e.src ? `s:${e.src}` : e.svg ? `v:${e.svg.slice(0, 120)}` : "");
|
|
1154
1268
|
const mobAll = (mob?.sections ?? []).flatMap((ms) => ms.elements.map((e) => ({ e, abs: ms.top + e.box.top, sec: ms })));
|
|
1155
1269
|
const byKey = new Map(mobAll.map((r) => [r.e.key, r]));
|
|
@@ -1212,9 +1326,12 @@ export function mergeCaptures(desk, mob) {
|
|
|
1212
1326
|
s.elements.forEach((e, j) => (matchesOf[i][j] ??= bySigPick(e, (r) => r.abs >= frames[i] && r.abs < end)));
|
|
1213
1327
|
});
|
|
1214
1328
|
const relative = (r, frameTop) => ({ ...r.e, box: { ...r.e.box, top: Math.round(r.abs - frameTop) } });
|
|
1329
|
+
// the mobile layout of a section is known when the same band exists there (a header whose desktop nav
|
|
1330
|
+
// collapses into a burger matches little, yet what is missing IS hidden) or enough of it matched
|
|
1331
|
+
const reliableAt = (i) => !!mob && ((keysHold && mobSec.has(desk.sections[i].key)) || desk.sections[i].elements.length === 0 || matchesOf[i].filter(Boolean).length / desk.sections[i].elements.length >= 0.3);
|
|
1215
1332
|
const sections = desk.sections.map((s, i) => {
|
|
1216
1333
|
const hits = matchesOf[i];
|
|
1217
|
-
const reliable =
|
|
1334
|
+
const reliable = reliableAt(i);
|
|
1218
1335
|
const fTop = frames[i];
|
|
1219
1336
|
const fEnd = i + 1 < frames.length ? frames[i + 1] : mobEnd;
|
|
1220
1337
|
const sec = {
|
|
@@ -1234,8 +1351,7 @@ export function mergeCaptures(desk, mob) {
|
|
|
1234
1351
|
if (used.has(r))
|
|
1235
1352
|
continue;
|
|
1236
1353
|
const i = frameOf(r.abs);
|
|
1237
|
-
|
|
1238
|
-
if (!desk.sections[i] || (desk.sections[i].elements.length && hits.filter(Boolean).length / desk.sections[i].elements.length < 0.3))
|
|
1354
|
+
if (!desk.sections[i] || !reliableAt(i))
|
|
1239
1355
|
continue;
|
|
1240
1356
|
const el = toEl(relative(r, frames[i]), undefined, km);
|
|
1241
1357
|
mobileOnly(el, true);
|
|
@@ -108,6 +108,9 @@ export function ensureOAuthSchema(pool) {
|
|
|
108
108
|
scope text,
|
|
109
109
|
expires_at bigint NOT NULL
|
|
110
110
|
);
|
|
111
|
+
ALTER TABLE oauth_codes ADD COLUMN IF NOT EXISTS wsid text;
|
|
112
|
+
ALTER TABLE oauth_access_tokens ADD COLUMN IF NOT EXISTS wsid text;
|
|
113
|
+
ALTER TABLE oauth_refresh_tokens ADD COLUMN IF NOT EXISTS wsid text;
|
|
111
114
|
`);
|
|
112
115
|
return true;
|
|
113
116
|
}
|
|
@@ -235,6 +235,8 @@ function authHeaders(config, orgId) {
|
|
|
235
235
|
Authorization: `Bearer ${config.jwt}`,
|
|
236
236
|
Cookie: `jwt=${config.jwt}`,
|
|
237
237
|
};
|
|
238
|
+
if (config.sessionId)
|
|
239
|
+
headers["x-session-id"] = config.sessionId;
|
|
238
240
|
const org = orgId ?? config.orgId;
|
|
239
241
|
if (org != null && `${org}` !== "")
|
|
240
242
|
headers["x-org-id"] = `${org}`;
|
|
@@ -335,7 +337,7 @@ export function buildRequestRedacted(config, name, source, orgId) {
|
|
|
335
337
|
return {
|
|
336
338
|
method: req.method,
|
|
337
339
|
url: req.url,
|
|
338
|
-
headers: { ...req.headers, Authorization: "Bearer ***JWT***", Cookie: "jwt=***JWT***" },
|
|
340
|
+
headers: { ...req.headers, Authorization: "Bearer ***JWT***", Cookie: "jwt=***JWT***", ...(config.sessionId ? { "x-session-id": "***" } : {}) },
|
|
339
341
|
body: mask(req.body).slice(0, 400) + (req.body.length > 400 ? `… (${req.body.length} bytes)` : ""),
|
|
340
342
|
};
|
|
341
343
|
}
|
|
@@ -552,7 +554,7 @@ export function buildUpdateRequestRedacted(config, pageId, source) {
|
|
|
552
554
|
return {
|
|
553
555
|
method: "POST",
|
|
554
556
|
url: `${config.base}${UPDATE_ENDPOINT}`,
|
|
555
|
-
headers: { ...authHeaders(config), Authorization: "Bearer ***JWT***", Cookie: "jwt=***JWT***" },
|
|
557
|
+
headers: { ...authHeaders(config), Authorization: "Bearer ***JWT***", Cookie: "jwt=***JWT***", ...(config.sessionId ? { "x-session-id": "***" } : {}) },
|
|
556
558
|
body: body.replace(config.jwt, "***JWT***").slice(0, 400) + (body.length > 400 ? `… (${body.length} bytes)` : ""),
|
|
557
559
|
};
|
|
558
560
|
}
|
|
@@ -562,7 +564,7 @@ export function buildAppendRequestRedacted(config, pageId, sections) {
|
|
|
562
564
|
return {
|
|
563
565
|
method: "POST",
|
|
564
566
|
url: `${config.base}${APPEND_ENDPOINT}`,
|
|
565
|
-
headers: { ...authHeaders(config), Authorization: "Bearer ***JWT***", Cookie: "jwt=***JWT***" },
|
|
567
|
+
headers: { ...authHeaders(config), Authorization: "Bearer ***JWT***", Cookie: "jwt=***JWT***", ...(config.sessionId ? { "x-session-id": "***" } : {}) },
|
|
566
568
|
body: body.replace(config.jwt, "***JWT***").slice(0, 400) + (body.length > 400 ? `… (${body.length} bytes)` : ""),
|
|
567
569
|
};
|
|
568
570
|
}
|
|
@@ -872,7 +874,7 @@ export function buildPublishRequestRedacted(config, pageId, source, opts = {}, w
|
|
|
872
874
|
return {
|
|
873
875
|
method: "POST",
|
|
874
876
|
url: publishUrl(config, pageId, willRender),
|
|
875
|
-
headers: { ...authHeaders(config), Authorization: "Bearer ***JWT***", Cookie: "jwt=***JWT***" },
|
|
877
|
+
headers: { ...authHeaders(config), Authorization: "Bearer ***JWT***", Cookie: "jwt=***JWT***", ...(config.sessionId ? { "x-session-id": "***" } : {}) },
|
|
876
878
|
body: body.replace(config.jwt, "***JWT***").slice(0, 600) + (body.length > 600 ? `… (${body.length} bytes)` : ""),
|
|
877
879
|
rendered: willRender,
|
|
878
880
|
};
|
|
@@ -1030,6 +1032,7 @@ export async function uploadImageToCollection(config, bytes, filename, contentTy
|
|
|
1030
1032
|
Accept: "application/json, text/plain, */*", // builder host: application/json alone → 406
|
|
1031
1033
|
Authorization: `Bearer ${config.jwt}`,
|
|
1032
1034
|
Cookie: `jwt=${config.jwt}`,
|
|
1035
|
+
...(config.sessionId ? { "x-session-id": config.sessionId } : {}),
|
|
1033
1036
|
"x-org-id": `${org}`,
|
|
1034
1037
|
},
|
|
1035
1038
|
body: form,
|
package/dist/smoke.js
CHANGED
|
@@ -1501,6 +1501,8 @@ console.log("== config: named environment presets (local/staging/prod) ==");
|
|
|
1501
1501
|
check("previewBase defaults to www.webcake.me without a preset", readConfig({ base: "https://api.example.com", jwt: "t" }).config?.previewBase === "https://www.webcake.me");
|
|
1502
1502
|
check("explicit previewBase overrides the preset", readConfig({ env: "prod", previewBase: "https://p.test/", jwt: "t" }).config?.previewBase === "https://p.test");
|
|
1503
1503
|
check("x-webcake-preview-base header parsed", configFromHeaders({ "x-webcake-preview-base": "https://p.example" }).previewBase === "https://p.example");
|
|
1504
|
+
check("x-webcake-session-id header → config.sessionId", readConfig({ ...configFromHeaders({ "x-webcake-jwt": "t", "x-webcake-session-id": "w" }), env: "prod" }).config?.sessionId === "w");
|
|
1505
|
+
check("no session id → config.sessionId undefined", readConfig({ env: "prod", jwt: "t" }).config?.sessionId === undefined);
|
|
1504
1506
|
check("preview url from a path → preview host (not builder)", toPreviewUrl(localCfg, "/preview/abc") === "http://preview.localhost:5800/preview/abc");
|
|
1505
1507
|
check("preview url from an absolute api url → preview host", toPreviewUrl(localCfg, "http://localhost:5800/preview/abc?x=1") === "http://preview.localhost:5800/preview/abc?x=1");
|
|
1506
1508
|
check("preview url passthrough when empty", toPreviewUrl(localCfg, undefined) === undefined);
|
|
@@ -1534,6 +1536,8 @@ console.log("== login: connect URL + loopback callback parsing (offline) ==");
|
|
|
1534
1536
|
check("connect url joins with & when a query already exists", buildConnectUrl("https://x.test/c?a=1", "http://127.0.0.1:1/callback", "s").includes("?a=1&redirect_uri="));
|
|
1535
1537
|
const okCb = parseCallback("/callback?token=tok&state=abc", "abc");
|
|
1536
1538
|
check("callback with token+state accepted", okCb.ok && okCb.token === "tok", okCb);
|
|
1539
|
+
const wsidCb = parseCallback("/callback?token=tok&wsid=w&state=abc", "abc");
|
|
1540
|
+
check("callback carries the optional wsid", wsidCb.ok && wsidCb.sessionId === "w" && okCb.ok && okCb.sessionId === undefined, wsidCb);
|
|
1537
1541
|
const wrongState = parseCallback("/callback?token=tok&state=other", "abc");
|
|
1538
1542
|
check("callback with wrong state rejected (400)", !wrongState.ok && wrongState.status === 400, wrongState);
|
|
1539
1543
|
const noState = parseCallback("/callback?token=tok", "abc");
|
package/dist/tools/clone.js
CHANGED
|
@@ -58,7 +58,7 @@ export async function cloneToDraft(domain, target, name) {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
export function registerCloneTools(server, domain) {
|
|
61
|
-
server.tool("clone_page", "Clones any web page into a Webcake landing page by MEASURING it in a real browser (headless Chrome via Playwright, JavaScript executed — works for React/Vue/Next sites too). The page is loaded at 1200 px and at 420 px; every visible text, image, button, painted box, divider, svg icon and form is recorded with its box, rotation and typography and placed on the landing canvas: desktop boxes scaled onto 960, mobile boxes as measured on 420 (elements the mobile layout hides get config.hide on mobile; mobile-only ones are hidden on desktop). Links become open_link events; fixed elements are pinned; a sticky header becomes the section's native sticky (a-t). Effects, native first: gradients (also gradient text), filters/backdrop blur, rotation and AOS / animate.css / WOW entrance animations map onto native settings; an overflow:hidden box whose content spills out becomes a clipping group (custom_css overflow:hidden); the page's own :hover rules (also ancestor rules like .card:hover img, applied on the element itself) + transitions and its looping CSS animations (@keyframes) become settings.extra_css scoped to #w-<id> (the one thing no native setting covers); icon-font stylesheets go to settings.bhet; self-hosted @font-face fonts to settings.fontGroups. Forms keep every control as its native field (select with options, radio, checkbox-group, textarea, date, file), also forms without a <form> tag. Interactive parts stay interactive, natively: accordions / FAQs (<details>, Bootstrap collapse, aria-expanded panels) become a click→collapse on the question that collapses the answer on load; tab sets ([role=tabpanel], .tab-pane) become a carousel switched by its tab buttons (change_tab); modals hidden on load (.modal, <dialog>, [role=dialog], .popup…) become landing popups, and the buttons/links that open them get open_popup; #anchor links get scroll_to; sliders (Swiper, Slick, Splide, Owl, Bootstrap carousel, Glide, Flickity, Keen, Embla) become a carousel of slides (hidden slides measured too, library clones skipped); YouTube / Vimeo / <video> become the video element. Multi-colour svgs (logos, illustrations, gradients) become images of themselves; single-colour icons stay native svg masks. The source is validated like a save and cached: the result carries `draft_id` — save it with create_page({ draft_id, dry_run:false }). Robust to real sites: app shells that scroll inside a full-height box are unlocked, reveal-on-scroll content is scrolled into its shown state, a tall <main> is split into its sections, overlapping (angled) sections keep their stacking, content clipped by overflow:hidden is cropped (images keep a crop), measured text heights are kept (config.virtualHeight), every colour is rgba(), and desktop/mobile elements are matched by DOM path, else by their text / picture. Approximations: an ancestor :hover fires when the element itself is hovered, other iframes become html-box embeds, content a site renders differently on each load may shift. Needs Playwright on the host (playwright-core + Chrome, or CHROME_BIN). No credentials, no writes.", {
|
|
61
|
+
server.tool("clone_page", "Clones any web page into a Webcake landing page by MEASURING it in a real browser (headless Chrome via Playwright, JavaScript executed — works for React/Vue/Next sites too). The page is loaded at 1200 px and at 420 px; every visible text, image, button, painted box, divider, svg icon and form is recorded with its box, rotation and typography and placed on the landing canvas: desktop boxes scaled onto 960, mobile boxes as measured on 420 (elements the mobile layout hides get config.hide on mobile; mobile-only ones are hidden on desktop). Links become open_link events; fixed elements are pinned; a sticky header becomes the section's native sticky (a-t). Effects, native first: gradients (also gradient text), filters/backdrop blur, rotation and AOS / animate.css / WOW entrance animations map onto native settings; an overflow:hidden box whose content spills out becomes a clipping group (custom_css overflow:hidden); the page's own :hover rules (also ancestor rules like .card:hover img, applied on the element itself) + transitions and its looping CSS animations (@keyframes) become settings.extra_css scoped to #w-<id> (the one thing no native setting covers); icon-font stylesheets go to settings.bhet; self-hosted @font-face fonts to settings.fontGroups. Forms keep every control as its native field (select with options, radio, checkbox-group, textarea, date, file), also forms without a <form> tag. Interactive parts stay interactive, natively: accordions / FAQs (<details>, Bootstrap collapse, aria-expanded panels) become a click→collapse on the question that collapses the answer on load; tab sets ([role=tabpanel], .tab-pane) become a carousel switched by its tab buttons (change_tab); modals hidden on load (.modal, <dialog>, [role=dialog], .popup…) become landing popups, and the buttons/links that open them get open_popup; #anchor links get scroll_to; sliders (Swiper, Slick, Splide, Owl, Bootstrap carousel, Glide, Flickity, Keen, Embla) become a carousel of slides (hidden slides measured too, library clones skipped); YouTube / Vimeo / <video> become the video element. Multi-colour svgs (logos, illustrations, gradients) become images of themselves; single-colour icons stay native svg masks. The source is validated like a save and cached: the result carries `draft_id` — save it with create_page({ draft_id, dry_run:false }). Robust to real sites: cookie / consent / newsletter overlays are dismissed (their accept / close clicked) and chat widgets left out before measuring, a fixed site header becomes the sticky first section, app shells that scroll inside a full-height box are unlocked, reveal-on-scroll content is scrolled into its shown state, a tall <main> (also through a lone wrapper div) is split into its sections, overlapping (angled) sections keep their stacking, content clipped by overflow:hidden is cropped (images keep a crop), measured text heights are kept (config.virtualHeight), every colour is rgba(), and desktop/mobile elements are matched by DOM path, else by their text / picture. Approximations: an ancestor :hover fires when the element itself is hovered, other iframes become html-box embeds, content a site renders differently on each load may shift. Needs Playwright on the host (playwright-core + Chrome, or CHROME_BIN). No credentials, no writes.", {
|
|
62
62
|
url: z.string().optional().describe("Public http(s) URL of the page to clone."),
|
|
63
63
|
html: z.string().optional().describe("Raw HTML instead of a URL (a saved page / an exported file). Pass base_url so its relative images, stylesheets and fonts load."),
|
|
64
64
|
base_url: z.string().optional().describe("With html: the page's original URL — relative assets (images, CSS, fonts) resolve against it, as if the page were loaded from there."),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webcake-landing-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "MCP server exposing Webcake landing-page element schemas + AI usage hints, and persisting LLM-generated page sources to a Webcake backend.",
|
|
5
5
|
"mcpName": "io.github.vuluu2k/webcake-landing-mcp",
|
|
6
6
|
"type": "module",
|