A professional postMessage-based RPC library that creates and maintains secure communication between window objects, like a web page and an iframe inside it.
A fork of Chamaileon's original plugin-interface, enhanced and maintained independently with TypeScript-first approach and modern tooling.
npm install @micskeil/postmessage-rpc
import { initInlinePlugin } from '@micskeil/postmessage-rpc';
const plugin = await initInlinePlugin(
{
data: { userId: 123 },
settings: { theme: 'dark' },
hooks: {
onSave: async (data) => {
console.log('Saved:', data);
}
}
},
{
src: 'https://your-plugin-url.com',
container: document.getElementById('plugin-container'),
timeout: 5000
}
);
// Call plugin methods
const result = await plugin.methods.getData();
// Cleanup
plugin.destroy();
import { providePlugin } from '@micskeil/postmessage-rpc';
const { data, settings, hooks } = await providePlugin({
hooks: ['onSave', 'onClose'],
methods: {
getData: async () => {
return { status: 'ok', data: myData };
},
setTheme: async (theme) => {
applyTheme(theme);
return { success: true };
}
},
validator: ({ data, settings }) => {
if (!data.userId) throw new Error('User ID is required');
}
});
// Use data and settings from parent
console.log('Initialized with:', data, settings);
// Call parent hooks
await hooks.onSave({ content: 'Updated' });
Embedded iframes within your page layout. Perfect for cards, widgets, or multiple instances.
import { initInlinePlugin } from '@micskeil/postmessage-rpc';
const plugin = await initInlinePlugin(config, options);
Modal-style overlays that cover the entire viewport with show/hide animations and optional splash screens.
import { initFullscreenPlugin } from '@micskeil/postmessage-rpc';
const plugin = await initFullscreenPlugin(config, options);
plugin.show(); // Animate in
plugin.hide(); // Animate out
The repository includes an interactive sticky notes demo demonstrating:
Run the examples:
npm install
npm run examples
Then open your browser to http://localhost:8765/examples/
Contributions are welcome! Please see GitHub Issues to report bugs or request features.
git checkout -b feat/my-featurenpm testnpm run lint-fix && npm run buildnpm run dev # Development server with hot reload
npm run build # Build the library
npm run test # Run tests with coverage
npm run test:watch # Watch mode
npm run lint-fix # Lint and auto-fix
GitHub Actions automatically:
MIT - See LICENSE file for details.
Fork of Chamaileon's original plugin-interface | View on NPM