Workers crash while rewriting HTML

I have a worker that transforms html in output from a proxied heroku app. Code is mostly a straightforward modification of the HTMLRewriter example. It just happens that the script crashes returning error 500 ca. 20% of the runs. It apparently happens on css files, because the net effect on the app is that sometimes the css don’t load and the console reports http error 500 on css files.
The workers are attached to the route* and only process text/html and, trying with curl, the server returns the correct content-type.
Code excerpt:

    if (contentType.startsWith('text/html')) {
      return rewriter.transform(res);
    } else {
      return res;

I’m somewhat stuck because I can’t really understand what’s happening because I could not find any way to have a log from the workers (so I can understand which request causes the problem).
Any hint is appreciated :slightly_smiling_face:

You can debug in a couple of easy ways, take a look at:

And specifically:

The easiest thing is probably to use console.log in your worker and then check the logs section of your worker in the dashboard to see the live events.

Thank you, I’ll try. The problem is that the script is invoked on the HTML sent from a (proxied) site, so I’m not sure how to trigger it without redirecting the actual site :slightly_smiling_face: and the traffic is significant (say 10k requests per hours), but I’ll try to. Thank you again