LeftyLlama
LeftyLlama
CDCloudflare Developers
Created by LeftyLlama on 1/8/2025 in #workers-help
Prevent HTMLRewriter Element interface conflicting with browser Element interface
I'm working on a project where the client and worker share type definitions. Upon adding the type definitions for @cloudflare/workers-types, my client code started having issues compiling, which after some investigation I found was caused by the Element interface used by the HTMLRewriter API conflicting with the browser Element interface. More specifically, Element.append, Element.prepend, Element.before, and Element.after take a string argument for HTMLRewriter, but take Nodes as arguments in the browser. I am still new to TypeScript so I might just be structuring my project poorly, but I'm wondering if there's a way to apply these type definitions to only the worker portion of my project (it is in a separate folder within the project folder).
1 replies
CDCloudflare Developers
Created by LeftyLlama on 11/28/2024 in #pages-help
WebSockets: Uncaught (in response) Error: The script will never generate a response.
I have a very simple function that listens for WebSocket connections and sends the current time whenever a message is received:
export const onRequest: PagesFunction = context => {
const upgradeHeader = context.request.headers.get("Upgrade")
if (upgradeHeader !== "websocket") {
return new Response("Expected websocket", { status: 400 })
}

const [client, server] = Object.values(new WebSocketPair());

server.accept();
server.addEventListener("message", () => {
server.send((Date.now()).toString());
});

return new Response(null, {
status: 101,
webSocket: client
});
}
export const onRequest: PagesFunction = context => {
const upgradeHeader = context.request.headers.get("Upgrade")
if (upgradeHeader !== "websocket") {
return new Response("Expected websocket", { status: 400 })
}

const [client, server] = Object.values(new WebSocketPair());

server.accept();
server.addEventListener("message", () => {
server.send((Date.now()).toString());
});

return new Response(null, {
status: 101,
webSocket: client
});
}
The script is working fine but every time the WebSocket is closed by the client, the following error is logged:
✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.
✘ [ERROR] Uncaught (in response) Error: The script will never generate a response.
The only information I've seen about this error has to do with either Promises or external libraries, neither of which I am using so I am confused as to what is causing this error message.
2 replies
CDCloudflare Developers
Created by LeftyLlama on 7/20/2024 in #workers-help
Dynamic image rendering with Workers
I'd like to use Cloudflare Workers to dynamically create and serve images, but all of the rendering packages I've found have native dependencies or otherwise don't run on the Workers platform. Tom Sherman's approach (https://tom-sherman.com/blog/dynamic-og-image-cloudflare-workers) is close to what I'd like but I'd rather not use the browser rendering API if possible
3 replies
CDCloudflare Developers
Created by LeftyLlama on 4/7/2024 in #workers-help
Worker not finding module when "node:" prefix is used
I'm trying to import an npm module, but if I try to import it with the "node:" prefix as the docs say, I get a "no such module" error. If I remove the "node:" prefix though it is able to find the module but then of course it has compatibility issues, so I assume this isn't what I want. How should I be importing the module? I have enabled nodejs_compat in my wrangler.toml file
3 replies
CDCloudflare Developers
Created by LeftyLlama on 11/4/2023 in #pages-help
ERR_SSL_VERSION_OR_CIPHER_MISMATCH on newly deployed Pages site
I've just deployed a new Pages site, and for whatever reason I'm getting an ERR_SSL_VERSION_OR_CIPHER_MISMATCH error when I try to access it. The site works just fine testing locally. I am making use of Pages Functions in advanced mode, and using Node.js compatibility mode, which I ensured is enabled in the dashboard. My guess is this has something to do with the recent outages, since some services aren't fully back online yet, but I want to make sure I'm not doing something stupid. Pages.dev URL: https://3b15dd82.push-notif-bonk.pages.dev/ Account ID: 4d752d329fbed0b32b01f13e90031e01 Errors: None on Cloudflare's end, ERR_SSL_VERSION_OR_CIPHER_MISMATCH in Chrome, equivalent errors in other browsers
7 replies