`require-post-message-target-origin` shouldn't trigger for incompatible APIs
See original GitHub issueWhat’s wrong
I’m currently developing a browser extension that communicates with native software:
import { browser, Runtime } from 'webextension-polyfill-ts'
const nativePort: Runtime.Port = browser.runtime.connectNative(APPLICATION_ID)
nativePort.postMessage({ cmd: 'Version' }) // (x) Missing the `targetOrigin` argument.
Which rule is buggy
require-post-message-target-origin
is triggered but the method only accepts one argument (see runtime.Port).
Ideas
- Enforce the name of the variable to be
window
,document
or the likes. - Check the type of the variable or the existence of the import
'webextension-polyfill'
/'webextension-polyfill-ts'
. - Add a warning for web extension developers here: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v34.0.1/docs/rules/require-post-message-target-origin.md
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:20 (2 by maintainers)
Top Results From Across the Web
Running inlined webworker code from within typescript project
When I put the second argument like postMessage(result, "*") , it caused ... So, the second argument is not optional, it shouldn't be...
Read more >Intermittently getting "Failed to execute 'postMessage' on ...
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://js.stripe.com') does not match the recipient window's ...
Read more >Window.postMessage() - Web APIs | MDN
The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it ...
Read more >Cookieless Tracking For Cross-site Iframes | Simo Ahava's blog
Same-Origin Policy prevents cross-origin access to embedded resources. You need either a postMessage API for this, or you need Google Analytics ...
Read more >The pitfalls of postMessage - Detectify Labs
The postMessage API is an alternative to JSONP, XHR with CORS ... if the target window is at the target origin when sending...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So
require-post-message-target-origin
should be disabled by default for.ts
files in the recommended config.I think we should turn this rule off…