1. Interactions with Sitecore

Get the page HTML

Version: 0.4

Required extension points: any SitecoreAI Page builder extension point

Required SDK packages: client

Required API access: none

Before you begin
  • Complete the SDK quick start. In the quick start, you make your first query by running client.query("application.context").

If your app uses any of the SitecoreAI Page builder extension points, you can retrieve the rendered HTML of the currently open page. The returned HTML is the rendered canvas output, with editing chrome and frames removed, so it reflects what the page looks like to a site visitor rather than the Page builder editing experience.

Ideas for using the page HTML

Consider using this method to build functionalities such as:

  • Overlays that analyze or annotate the current page based on its rendered markup.
  • Automation workflows that act on the page content without you having to reconstruct it from field data.
  • Content-driven actions, such as passing the page HTML to a downstream service.
  • Content reuse, such as copying rendered content into another system.
Note

This method only returns the raw rendered HTML of the page. The Marketplace SDK doesn't parse or transform this HTML for you, and it doesn't provide any UI components for displaying it. Your Marketplace app is responsible for handling the returned markup.

To get the page HTML:

  1. In the SDK initialization code where you run the useMarketplaceClient hook, in the Effect Hook, below the "application.context" query, call getPageHTML(), then save your changes:

    // Retrieve the rendered HTML of the current page
    client.getPageHTML()
      .then((html) => {
        console.log("Success retrieving page HTML:", html);
      })
      .catch((error) => {
        console.error("Error retrieving page HTML:", error);
      });
  2. In the SitecoreAI Page builder, open your web browser's console, refresh the page, then open your Marketplace app.

  3. In the console, find the log for Success retrieving page HTML and inspect the returned value. The value is a string containing the rendered HTML of the current page.

Important

This method requires that the SitecoreAI environment where your app is installed supports the page HTML capability. If the host doesn't support it, the request fails. Make sure to handle this in your app, for example, by using .catch() as shown in the previous example.

If you have suggestions for improving this article, let us know!