{"id":29884680,"url":"https://github.com/panta82/iframe_bridge","last_synced_at":"2025-07-31T15:06:04.435Z","repository":{"id":57271504,"uuid":"104845574","full_name":"panta82/iframe_bridge","owner":"panta82","description":"Very basic wrapper around window.postMessage.","archived":false,"fork":false,"pushed_at":"2017-10-04T13:32:57.000Z","size":31,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-31T12:26:39.251Z","etag":null,"topics":["iframe","javascript","npm","postmessage","postmessage-library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/panta82.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-26T06:35:45.000Z","updated_at":"2025-07-20T07:30:12.000Z","dependencies_parsed_at":"2022-09-08T21:41:53.628Z","dependency_job_id":null,"html_url":"https://github.com/panta82/iframe_bridge","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/panta82/iframe_bridge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panta82%2Fiframe_bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panta82%2Fiframe_bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panta82%2Fiframe_bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panta82%2Fiframe_bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panta82","download_url":"https://codeload.github.com/panta82/iframe_bridge/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panta82%2Fiframe_bridge/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268056944,"owners_count":24188610,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iframe","javascript","npm","postmessage","postmessage-library"],"created_at":"2025-07-31T15:05:48.908Z","updated_at":"2025-07-31T15:06:04.426Z","avatar_url":"https://github.com/panta82.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IFrameBridge\n\nVery basic wrapper around window.postMessage. Handles handshaking and JSON conversion. Makes sure you don't lose any messages.\n\nInstall from npm:\n\n```bash\nnpm install --save iframe_bridge\n```\n\nThen in your ES6+ code:\n\n```javascript\nconst IFrameBridge = require('iframe_bridge');\n```\n\nor\n\n```javascript\nimport IFrameBridge from 'iframe_bridge';\n```\n\n### Usage\n\n`iframe_bridge.js` file is the compiled browser-ready version of the library. If you reference it with `\u003cscript\u003e` tag, the constructor will become available globally as `window.BrowserBridge`. You can also require it from within an ES6 app with your own build system (see above).\n\nExample usage:\n\n(index.html)\n\n```html\n\u003cscript src=\"../dist/iframe_bridge.js\"\u003e\u003c/script\u003e\n\n\u003ciframe id=\"iframe\" src=\"iframe.html\"\u003e\u003c/iframe\u003e\n\n\u003cscript\u003e\n\tvar iFrame = document.getElementById('iframe');\n\n\t// Create an instance of bridge. By giving it iFrame's window as targetWindow,\n\t// you indicate this instance will work in \"server mode\",\n\t// and attempt to initiate connection. \n\tvar bridge = new IFrameBridge({\n\t\ttargetWindow: iFrame.contentWindow\n\t});\n\t\n\t\n\t// You then attach your event handlers. You should do this before calling init.\n\tbridge.on('response_from_iframe', (data) =\u003e {\n\t\tconsole.log(data); // \"Hello back\"\n\t});\n\n\t// Once you call init, we will start trying to connect to the iframe\n\t// If you want to wait, just attach .then() to this call, it will return a promise.\n\tbridge.init();\n\t\n\t// Any messages you post here, before we are connected, will be queued\n\t// and flushed once connection is established.\n\tbridge.postMessage('event_from_parent', {\n\t\tmessage: 'Hello'\n\t});\n\u003c/script\u003e\n```\n\n(iframe.html)\n\n```html\n\u003cscript src=\"../dist/iframe_bridge.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n\t// Create an instance of the bridge without giving it targetWindow.\n\t// The parent's window will be determined from the handshake message.\n\tvar bridge = new IFrameBridge();\n\t\n\t// You can also listen to the generic \"message\" event. You will get all received events here.\n\tbridge.on('message', (payload) =\u003e {\n\t\tif (payload.name === 'event_from_parent' \u0026\u0026 payload.data.message === 'Hello') {\n\t\t\tbridge.postMessage('response_from_iframe', 'Hello back');\n\t\t}\n\t});\n\t\n\t// Call init to start listening for handshake\n\tbridge.init();\n\u003c/script\u003e\n```\n\nYou can see a working example here: [tester/index.html](./tester/index.html).\n\n### Additional options\n\nCheck out `DEFAULT_OPTIONS` inside [IFrameBridge.js](lib/IFrameBridge.js) for the full list with comments.\n\nThis object will be available (and mutable) on `IFrameBridge.DEFAULT_OPTIONS`.\n\n### License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanta82%2Fiframe_bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanta82%2Fiframe_bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanta82%2Fiframe_bridge/lists"}