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

@drupal-canvas/extensions

v0.0.3

Published

API for building extensions for Drupal Canvas

Readme

Drupal Canvas Extensions API

JavaScript library for building Drupal Canvas extensions. Extensions are embedded web applications that can access and respond to data inside the Drupal Canvas app in real-time.

Installation

npm install @drupal-canvas/extensions

Getting started

To build a Drupal Canvas extension, create a web application with your technology of choice, and make sure it can be embedded in an iframe.

Then create a Drupal module with a [your-module-name].canvas_extension.yml file to define your extension's metadata:

canvas_test_extension: # ID of your extension. You can specify multiple extensions in this file.
  name: Example Extension
  description: A brief description of what your example does.
  url: index.html # Path to local HTML file shipped in your module's codebase, or a remote URL.
  icon: icon.svg # Path to local SVG file shipped in your module's codebase.
  type: canvas # Optional. Defaults to canvas. Other options: page, code-editor.
  api_version: 1.0
  permissions: # Optional. The user must have all listed permissions.
    - access content

Extension types determine where the extension appears in Canvas:

  • canvas: Opens from the Extensions panel while editing Canvas content. This is the default when type is omitted.
  • page: Opens as a full-page Canvas route at /canvas/app/{extension_id} and appears as a dedicated side menu link. Page extensions do not appear in the Extensions panel.
  • code-editor: Opens from the code editor.

Permissions are optional. When permissions are listed, users must have all of those permissions to access the extension. Page extensions without permissions are available to any user who can access the Canvas UI.

Page extension routing

Page extensions are hosted at /canvas/app/{extension_id}. They can also be opened with a deeper path, such as /canvas/app/{extension_id}/reports/weekly. Canvas forwards the deeper path to the extension iframe as a hash route: {extension_url}#/reports/weekly.

A page extension can update the parent Canvas URL when its internal route changes by sending a navigation message to the parent window:

window.parent.postMessage(
  {
    type: 'canvas:navigate',
    subPath: 'reports/weekly',
  },
  window.location.origin,
);

Canvas accepts navigation messages only from the active page extension iframe. The parent URL is updated without adding a new Canvas history entry, so Canvas back navigation returns to the previous Canvas screen instead of stepping through the extension's internal routes.

Example

For a full example, see the canvas_test_extension test module in the Drupal Canvas codebase.

Sandboxing model

Canvas extensions run in iframes with sandbox="allow-scripts allow-same-origin" for dialog extensions and sandbox="allow-scripts allow-same-origin allow-downloads" for page extensions. Because allow-same-origin is enabled, this is not a strong security boundary for extension code.

Installing an extension currently means installing the Drupal module that provides it, so site owners should treat extensions as trusted code. This model may change if Canvas supports registering extensions dynamically from arbitrary URLs in the future.

API

getPreviewHtml()

Get the current preview HTML.

Returns: Promise<string>

import { getPreviewHtml } from '@drupal-canvas/extensions';

const html = await getPreviewHtml();
console.log(html);

subscribeToPreviewHtml(callback)

Subscribe to preview HTML changes. The callback is called whenever the preview HTML updates.

Parameters:

  • callback: (html: string) => void - Function called with the updated HTML

Returns: () => void - Unsubscribe function

import { subscribeToPreviewHtml } from '@drupal-canvas/extensions';

const unsubscribe = subscribeToPreviewHtml((html) => {
  console.log('Preview HTML updated:', html);
});

// Later, when you want to stop listening:
unsubscribe();

getSelectedComponentUuid()

Get the UUID of the currently selected component.

Returns: Promise<string | undefined>

import { getSelectedComponentUuid } from '@drupal-canvas/extensions';

const uuid = await getSelectedComponentUuid();
if (uuid) {
  console.log('Selected component:', uuid);
} else {
  console.log('No component selected');
}

subscribeToSelectedComponentUuid(callback)

Subscribe to selected component UUID changes. The callback is called whenever the user selects a different component.

Parameters:

  • callback: (uuid: string | undefined) => void - Function called with the selected component UUID

Returns: () => void - Unsubscribe function

import { subscribeToSelectedComponentUuid } from '@drupal-canvas/extensions';

const unsubscribe = subscribeToSelectedComponentUuid((uuid) => {
  if (uuid) {
    console.log('Component selected:', uuid);
  } else {
    console.log('No component selected');
  }
});

// Later, when you want to stop listening:
unsubscribe();