GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - devlsh/embed: Simple iFrame messaging for Vue.

BranchesTags
Open more actions menu

Latest commit

 

History

39 Commits
39 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.openchamber
.openchamber
 
 
.vscode
.vscode
 
 
demo
demo
 
 
docs
docs
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.manifest.json
.manifest.json
 
 
AGENTS.md
AGENTS.md
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
lefthook.yml
lefthook.yml
 
 
oxfmt.config.ts
oxfmt.config.ts
 
 
oxlint.config.ts
oxlint.config.ts
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
pnpm-workspace.yaml
pnpm-workspace.yaml
 
 
release.json
release.json
 
 
shim.d.ts
shim.d.ts
 
 
tsconfig.build.json
tsconfig.build.json
 
 
tsconfig.json
tsconfig.json
 
 
tsdown.config.ts
tsdown.config.ts
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

@devlsh/embed

Simple iFrame messaging for Vue.


NPM Downloads GitHub Stars Build Status Software License


  • Cross-origin iFrame IPC.
  • Two-way messaging and async responses.
  • The same API for parent and embedded pages.
  • Multiple iframe connections on the same page.
  • Vue 3 and TypeScript support.

Installation

$ npm install @devlsh/embed

Usage

Set up a host page at https://example.com and a client page at https://frame.example.com.

Use the same id in both components, otherwise they'll ignore eachothers messages.

Shared

import { type DefaultEventsMap } from '@devlsh/embed';

interface Yay {
  test: number;
}

export interface CustomEvents extends DefaultEventsMap {
  yay: (payload: Yay) => void;
}

Host

<template>
  <iframe ref="iframe" src="https://frame.example.com" title="Client page" sandbox="allow-scripts allow-same-origin" />
</template>

<script setup lang="ts">
  import { useEmbed, type DefaultEventsMap } from '@devlsh/embed';
  import { shallowRef } from 'vue';

  const iframe = shallowRef<HTMLIFrameElement>();

  const host = useEmbed<CustomEvents>('host', {
    id: 'shared-id',
    iframe,
    remote: 'https://frame.example.com',
  });

  host.events.on('yay', (payload) => {
    console.log(payload);
  });

  onMounted(() => {
    void host.send<string>('hello-world', { hello: 'world' });
  });
</script>

Client

<template>
  <button type="button" @click="submit">Send event</button>
</template>

<script setup lang="ts">
  import { useEmbed } from '@devlsh/embed';

  interface HelloWorld {
    hello: string;
  }

  const client = useEmbed<CustomEvents>('client', {
    id: 'shared-id',
    remote: 'https://example.com',
  });

  client.handle<HelloWorld>('hello-world', async ({ hello }) => {
    return hello === 'world' ? 'hey' : 'go away';
  });

  function submit() {
    client.post('yay', { test: 123 });
  }
</script>

Options

Option Type Default or required Description
id string Required Shared connection ID for the host and client. Use a different ID for each iframe connection.
timeout number 15000 Request timeout in milliseconds.
iframe Vue Ref<HTMLIFrameElement | undefined> Required in host mode Reference to the host's iframe element.
remote string '*' Remote origin for message checks and, when the target origin is readable, outgoing messages. See the security note below.
debug boolean false Enable debug logs for the connection.

Security Note

By default, if you don't supply a remote, the library will process all incoming messages and send events that any party can recieve. By setting this to a URL (See above example), you can limit this and hugely reduce the impact it has on security.

Contributing

Report bugs through issues or ask questions in Discussions. Report vulnerabilities privately as described in SECURITY.md.

For local development, pull requests, and other contributions, see the Contributing Guidelines.

License

@devlsh/embed is free and open-source software licensed under the MIT License.


devlsh.com  ·  GitHub: @devlsh  ·  X: @itsdevlsh

About

Simple iFrame messaging for Vue.

devlsh.com

Topics

asynccommunicationeventiframemessagingpostmessagetypescriptvue

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity

Stars

45 stars

Watchers

2 watching

Forks

2 forks
Report repository

Releases

Sponsor this project

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.