Lightweight library for injecting AB Tasty modules into an iframe, wiring postMessage events, and syncing module storage/config with the modules API.
Lightweight library for injecting AB Tasty modules into an iframe, wiring
postMessage events, and syncing module storage/config with the modules API.
- Loads a listener into an iframe and injects module runtime helpers.
- Fetches module config and source, then evaluates it in the iframe.
- Provides simple event, tracking, and storage plumbing between parent and iframe.
``bash`
npm install
Node 22+ is required.
`bash`
npm run build
`js
import injector, { updateAccessToken, setModuleApiBase } from './dist/index';
setModuleApiBase('https://modules-api.poc.abtastylab.com');
injector.inject({
iframeElement: document.getElementById('module-frame'),
ab: {
accessToken: '
accountId: '
moduleId: '
testId: '
env: 'production'
},
injectedCallback: () => console.log('injected')
});
// Optionally update token later
updateAccessToken(document.getElementById('module-frame'), '
`
inject accepts:
- iframeElement (required): target iframe element.ab
- (required): object containing access/module identifiers and config.script
- (optional): raw source code to inject instead of fetching from API.allowedOrigins
- (optional): allowlist for incoming postMessage events.'*'
Defaults to for backward compatibility.targetOrigin
- (optional): target origin for outgoing postMessage calls.'*'
Defaults to .injectedCallback
- Callback hooks: , readyCallback, waitCallback,heightUpdatedCallback
, eventCallback, trackCallback.
You can also set the modules API base URL globally:
`js
import { setModuleApiBase } from './dist/index';
setModuleApiBase('https://modules-api.poc.abtastylab.com');
`
- The iframe listener uses eval to run module code. Only use trusted sources.allowedOrigins
- If you enable , remember that srcdoc/data: iframes report"null"
origin as .
The entrypoint is src/index.js.dist/
Build output is written to .
The example test harness lives in examples/test.js and is not bundled into dist/`.