{"id":21195647,"url":"https://github.com/qiqiboy/pmer","last_synced_at":"2026-01-19T12:33:01.127Z","repository":{"id":57326387,"uuid":"204921664","full_name":"qiqiboy/pmer","owner":"qiqiboy","description":"Provide some powerful \u0026 helpful functions for Two-way communication with postMessage","archived":false,"fork":false,"pushed_at":"2024-09-26T21:59:42.000Z","size":37,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-30T13:48:40.248Z","etag":null,"topics":["broadcast","cross-domain","iframe","postmessage","two-way-communication"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/qiqiboy.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-28T12:02:49.000Z","updated_at":"2022-07-04T09:25:50.000Z","dependencies_parsed_at":"2024-11-20T19:33:38.559Z","dependency_job_id":"f6171cbf-47b4-4f37-8b7c-0c48cf6e4b68","html_url":"https://github.com/qiqiboy/pmer","commit_stats":null,"previous_names":["qiqiboy/pm-helper"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/qiqiboy/pmer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fpmer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fpmer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fpmer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fpmer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qiqiboy","download_url":"https://codeload.github.com/qiqiboy/pmer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqiboy%2Fpmer/sbom","scorecard":{"id":753713,"data":{"date":"2025-08-11","repo":{"name":"github.com/qiqiboy/pmer","commit":"4bc745184cf4c5f4db9944e59a692f19a54d53c2"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/13 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-22T20:58:49.789Z","repository_id":57326387,"created_at":"2025-08-22T20:58:49.789Z","updated_at":"2025-08-22T20:58:49.789Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28567896,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T08:53:44.001Z","status":"ssl_error","status_checked_at":"2026-01-19T08:52:40.245Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["broadcast","cross-domain","iframe","postmessage","two-way-communication"],"created_at":"2024-11-20T19:29:27.353Z","updated_at":"2026-01-19T12:33:01.105Z","avatar_url":"https://github.com/qiqiboy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pmer\n\n提供一些便捷的使用 [`postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) 的一些辅助方法\n\n\u003c!-- vim-markdown-toc GFM --\u003e\n\n* [安装](#安装)\n* [背景](#背景)\n* [使用](#使用)\n    - [`postMessage`](#postmessage)\n    - [`addListener`](#addlistener)\n    - [`addListenerOnce`](#addlisteneronce)\n\n\u003c!-- vim-markdown-toc --\u003e\n\n## 安装\n\n```bash\n$ npm install pmer --save\n```\n\n## 背景\n\n`postMessage`的使用本身已经非常简单了，但是实际应用中，由于`postMessage`和`addEventListener('message')`的强解耦，导致消息的`收` `发`变得非常离散。\n\n通过本项目提供的一些方法，可以更加简单的控制消息的监听与发送。\n\n你可以发送消息，并监听是否收到回复；也可以主动监听指定的`type`消息，并且回复该消息。\n\n## 使用\n\n`pmer`目前提供了以下几个方法供使用：\n\n### `postMessage`\n\n向目标窗口发送消息，返回一个 promise 对象。你可以通过该 promise 对象来判断是否成功发送了消息，并且如果目标窗口如果回复了该消息，你还可以通过 promise 回调收到传回来的数据。\n\n```typescript\n/**\n * 发送消息\n * @param {Window} target 目标窗口, window.opener/window.parent/HTMLIFrameElement.contentWindow...\n * @param {string} type 消息类型\n * @param {any} payload 消息体\n * @param {string} 可选，targetOrigin\n * @param {Transferable[]} 可选，transfer\n *\n * @return {Promise\u003cany\u003e} 返回promise，如果有收到回复消息，将会触发promose回调\n */\nexport declare function postMessage(\n    target: Window,\n    type: string,\n    payload?: any,\n    targetOrigin?: string,\n    transfer?: Transferable[]\n): Promise\u003cany\u003e;\n\n// 给父级窗口发送 DELETE_USER 消息\npostMessage(window.parent, 'DELETE_USER', 123);\n\n// 如果父级窗口有回复该消息，则可以通过promise监听结果\npostMessage(window.parent, 'DELETE_USER', 123).then(() =\u003e console.log('delete succeed!'));\n```\n\n### `addListener`\n\n监听当前窗口接受到的消息(只支持通过[`postMessage`](#postmessage)发送的消息)，并且可以回复该消息\n\n```typescript\n/**\n * 添加消息监听\n * @param {string|Array} msgTypes 要监听的消息类型，*表示任何消息\n * @param {Function} listener 监听方法\n * @param {Function} filter 可选，消息过滤，可以通过该方法过滤不符合要求的消息\n *\n * @return {function} 返回移除监听的方法\n */\nexport declare function addListener(\n    msgTypes: ListenerTypes,\n    listener: LisenterCall,\n    filter: (event: PMERMessageEvent\u003cT\u003e) =\u003e boolean\n): RemoveListener;\n\n// 监听 DELETE_USER 消息\naddListener('DELETE_USER', payload =\u003e {\n    console.log('message:', payload);\n});\n\n// 通过return一个值，可以回复该消息\naddListener('DELETE_USER', payload =\u003e {\n    return 'delete succeed!';\n});\n\n// 你也可以返回一个promise对象(这里使用async/await语法)：\n// postMessage(window, 'DELETE_USER', 123)\n//      .then(() =\u003e console.log('删除成功'), () =\u003e console.log('删除失败'))\naddListener('DELETE_USER', async userId =\u003e {\n    await fetch('/delete/user/' + userId);\n});\n\n// addListener调用后会返回一个清理函数，可以通过该函数随时移除当前的消息监听\nconst removeListener = addListener('DELETE_USER', () =\u003e {});\nremoveListener();\n\n// 可以通过第三个filter参数过滤一些不符合的消息，例如只接收来自指定域的消息\naddListener(\n    'DELETE_USER',\n    payload =\u003e {\n        console.log(payload);\n    },\n    event =\u003e event.origin === 'https://valid.domain.com'\n);\n```\n\n### `addListenerOnce`\n\n用法完全同`addListener`，唯一区别是当调用过一次后，会自动移除监听\n\n```typescript\n/**\n * 添加单次消息监听\n * @param {string|Array} msgTypes 要监听的消息类型，*表示任何消息\n * @param {Function} listener 监听方法\n * @param {Function} filter 可选，消息过滤，可以通过该方法过滤不符合要求的消息\n *\n * @return {function} 返回移除监听的方法\n */\nexport declare function addListenerOnce(\n    msgTypes: ListenerTypes,\n    listener: LisenterCall,\n    filter: (event: PMERMessageEvent\u003cT\u003e) =\u003e boolean\n): RemoveListener;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiqiboy%2Fpmer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqiqiboy%2Fpmer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiqiboy%2Fpmer/lists"}