I have multiple "children workers" that use HTMLRewriter() to change the HTML of response. What I am

I have multiple "children workers" that use HTMLRewriter() to change the HTML of response.
What I am trying to achieve is to trigger multiple workers with "parent worker".
I know you can use service bindings to bind another worker to it, but the problem I have is I need to run multiple workers and modify the responses accordingly.

For example: if I bind two child workers, one will change meta title (worker 1) and one meta description (worker 2).
What I need to achieve is firstly trigger worker1 with parent request, and then trigger worker 2 on response i get from worker 1, so i get all the HTML changes.

I have no problem getting response from worker 1, but I dont know how to combine worker 1 and worker 2 changes. What i tried is passing body of response from worker 1 to worker 2 fetch, like this:

    // Fetch the resource using childWorker1
    const childWorker1Response = await env.childWorker1.fetch(request.clone());

    // Fully consume the response body of childWorker1
    const childWorker1ResponseBody = await childWorker1Response.text();

    // Fetch a resource using childWorker2, passing the response body of childWorker1 as the POST body
    const childWorker2Response = await env.childWorker2.fetch(request.clone(), {
      method: 'POST',
      body: childWorker1ResponseBody
    });


But this does not seem to work.

Do you have any ideas what is wrong?
Any help would be greatly appreciated!
Was this page helpful?