npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rooks-ai/web-embed

v0.3.0

Published

Embed Rooks forms in web pages

Readme

@rooks-ai/web-embed

Embed Rooks forms in web pages.

Embed a form

Publish your form and add your host page's origin (for example, https://www.example.com) to the form's allowed domains. Use the final published form URL, including its custom domain if it has one.

With a package manager

pnpm add @rooks-ai/[email protected]

Add a container where the form should appear.

<div id="intake"></div>

Call embed() in the browser once the container exists.

import { embed } from '@rooks-ai/web-embed';

const form = embed('#intake', 'https://acme.rooks.app/form/intake', {
  answers: { first_name: 'Ada' },
});

// Call form.destroy() when the container is no longer needed.

With a script tag

The script tag pins the package version and uses subresource integrity to verify the bundle.

<div id="intake"></div>
<script
  src="https://cdn.jsdelivr.net/npm/@rooks-ai/[email protected]/dist/index.umd.js"
  integrity="sha384-A5e5ZSK4fnbNeLR2RXG61c0qQ0yeEiDNNj06U2IfSR8+8ta2OfaCaCjzY0Iv+8bi"
  crossorigin="anonymous"
></script>
<script>
  const form = RooksWebEmbed.embed('#intake', 'https://acme.rooks.app/form/intake');
</script>

With the <rooks-embed> element

Loading the SDK registers the <rooks-embed> element. Use the first <script> tag above (the one with integrity), without the RooksWebEmbed.embed() call. With the package, import it once in browser code:

import '@rooks-ai/web-embed';

Then add the element where the form should appear.

<rooks-embed src="https://acme.rooks.app/form/intake"></rooks-embed>

To send answers or listen for events, create the element in a script. Set answers before you add the element to the page.

const element = document.createElement('rooks-embed');
element.setAttribute('src', 'https://acme.rooks.app/form/intake');
element.answers = { first_name: 'Ada' };
element.addEventListener('completed', () => {
  showThankYouMessage();
});
document.querySelector('#intake').append(element);

API

embed(target, formUrl, options?) accepts a CSS selector or DOM element and an absolute HTTP(S) form URL. It returns a handle with on() and destroy().

| Option | Behavior | | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | answers | Optional object keyed by form answer name. Values can be strings, numbers, booleans, null, arrays, or objects. The SDK sends these directly to the iframe after it is ready. | | height | Defaults to 'auto', which follows the height reported by the form. Pass a number for a fixed height in pixels. | | onRedirect(url) | Called with a resolved HTTP(S) URL before navigating the host page. Return false to cancel the navigation. | | onError(error) | Called if the form gives no ready signal within 10 seconds. Check the form URL and the host origin named in the error. The browser reports the error by default. The embed still initializes if the form responds later. |

destroy() removes the iframe and its listeners.

The SDK keeps initial answers out of the iframe URL and sends them directly to the form's origin after it signals that it is ready. The handshake repeats on reload. A different page loaded into the iframe on the same origin can also receive those answers if it signals that it is ready.

The page at the form URL gets the answers and can navigate your page with a redirect. Use only the URL of your own published form. Never take the form URL from user input, a query parameter, or HTML that you do not control. This applies to embed() and to the src of <rooks-embed>.

Events

form.on(name, listener) adds a listener for a form event. form is the handle that embed() returns. The listener gets the event payload. on() returns a function that removes that listener.

const off = form.on('pageCompleted', ({ page }) => {
  updateProgressBar(page.index);
});

// Later, to stop listening:
off();
  • A listener gets only events that happen after you add it. Past events are not sent again.
  • Listeners keep working when the form reloads.
  • If a listener throws, the browser reports the error. The other listeners still run.
  • on() after destroy() adds nothing.

| Event | When it fires | Payload | | ---------------- | ------------------------------------------------------------------- | ------------------------------- | | loaded | The form loaded. | { responseId, answers } | | pageLoaded | The form shows a page. | { responseId, answers, page } | | pageCompleted | The responder completed a page. | { responseId, answers, page } | | responsesSaved | The form saved the answers. It fires after each save, autosave too. | { responseId, answers } | | completed | The responder completed the form, after the last responsesSaved. | { responseId, answers } |

  • responseId is the ID of the responder.
  • answers is an object keyed by the form's answer labels. It includes calculated variables.
  • page.index is the position of the page, from 0.
  • page.id is the page ID from the form. It is missing if the page has no ID.

If the form has a redirect, the redirect comes after completed.

Answers are often personal or health data. Do not log them or send them to analytics tools.

<rooks-embed>

| Attribute | Behavior | | --------- | ----------------------------------------------------------------------------------------------------- | | src | The absolute HTTP(S) URL of your published form. Without src, the element shows nothing. | | height | auto (the default) follows the height reported by the form. A number sets a fixed height in pixels. |

answers is a JavaScript property, not an attribute. It takes the same object as the answers option of embed(). Set it before you add the element to the page. If you set it to a different value later, the form reloads. A value equal to the current one does not reload the form. Do not put answers in the HTML or in the form URL.

A change to src or height also reloads the form. Removing the element removes the form.

The element fires the five events in the table above as CustomEvents. event.detail is the payload. The events do not bubble, so add listeners to the element itself.

element.addEventListener('pageLoaded', (event) => {
  updateProgressBar(event.detail.page.index);
});

The element also fires two events that you can cancel with event.preventDefault():

  • redirect: the form asks to navigate the host page. event.detail.url is the resolved HTTP(S) URL. Cancel the event to stay on the page.
  • error: the form did not respond within 10 seconds, or src is not an HTTP(S) URL. event.detail is the Error. If you do not cancel the event, the browser reports the error.

In TypeScript, document.createElement('rooks-embed') returns a RooksEmbedElement, and its addEventListener() knows the type of each event's detail.