question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`require-post-message-target-origin` shouldn't trigger for incompatible APIs

See original GitHub issue

What’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

  1. Enforce the name of the variable to be window, document or the likes.
  2. Check the type of the variable or the existence of the import 'webextension-polyfill'/'webextension-polyfill-ts'.
  3. 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:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
JounQincommented, Jul 12, 2021

That will be meaningless if this #1396 (comment) is true.

So require-post-message-target-origin should be disabled by default for .ts files in the recommended config.

2reactions
fiskercommented, Jul 2, 2021

I think we should turn this rule off…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found