Passing HTML content from extension to web page other than as a string

Is there a method to pass an HTML file in an extension to a web page via the content script or pass the HTML as a DOM element rather than a string?

Currently, the HTML that is passed is a string held in the background page as a template element and insertAdjacentHTML is used to add it to the document. From another question here I think a DOMParser could be used also on that string. But is it possible to pass the HTML from the extension to the page as a DOM tree rather than string or to reference an HTML file saved in the extension itself, rather than holding the HTML in a template element in the background page and passing as a string?

Thank you.

From content script to page, yes. I don’t think you can pass DOM elements between extension pages and content scripts though.

Thank you. Do you know if there is a way to convert an HTML file of the extension to a string to pass to the content script, rather than storing the HTML in a template element of the background page? and whether or not there is a down side to having a large amount of HTML in the background page of an extension? Thanks again.

You can load it using fetch/XHR.

Having a big dom tree for the bg page means it’ll use more ram.

Thank you. I wasn’t sure that a browser.runtime.getURL() would work in a fetch request. That ought to simplify my issue and reduce the extension’s use of RAM. Thanks agian.