I am trying to extract some data from a html page using html rewriter: ``` var htmlRewriter = new H

I am trying to extract some data from a html page using html rewriter:

var htmlRewriter = new HTMLRewriter();

                var title = '';
                var description = '';
                var favicon = '';
                var ogImage = '';

                htmlRewriter.on('title', {
                    text: (text) => {
                        title = text;
                    }
                });

                htmlRewriter.on('meta[name="description"]', {
                    element: (element) => {
                        description = element.getAttribute('content');
                    }
                });

                htmlRewriter.on('link[rel="icon"]', {
                    element: (element) => {
                        favicon = element.getAttribute('href');
                    }
                });

                htmlRewriter.on('meta[property="og:image"]', {
                    element: (element) => {
                        ogImage = element.getAttribute('content');
                    }
                });

                var content_response = new Response(html, {
                    headers: {
                        'Content-Type': 'text/html',
                    },
                });

                await (await htmlRewriter.transform(content_response)).text();

                console.log('meta data', { title, description, favicon, ogImage });

                return { title, description, favicon, ogImage };


I keep geting the error: An RPC stub was not disposed properly. You must call dispose() on all stubs in order to let the other side know that you are no longer using them. You cannot rely on the garbage collector for this because it may take arbitrarily long before actually collecting unreachable objects. As a shortcut, calling dispose() on the result of an RPC call disposes all stubs within it.
Was this page helpful?