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.

addEventListener for "message" not relayed from browser extension

See original GitHub issue

Current behavior

When testing a page where a browser extension content script sends a message via window.postMessage and a page is listening via window.addEventListener("message", ...) Cypress does not pass on this message.

Desired behavior

Cypress should pass on these events.

Test code to reproduce

https://github.com/kasbah/cypress-add-event-listener-repro

git clone https://github.com/kasbah/cypress-add-event-listener-repro
cd cypress-add-event-listener-repro
npm ci
npm serve
npm run test

To confirm that a similar test passes using playwright you can do:

npm run test-pw

Cypress Version

10.1.0

Other

May be related to https://github.com/cypress-io/cypress/issues/1567

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lmiller1990commented, Jun 27, 2022

Thanks for clarifying. I’ll try and take another look at this, sometime this week. It seems like there’s a few other blockers? I’m not sure I can prioritize this one right now, but I’m definitely interested in the general “testing extensions with Cypress” problem, so I’ll try and loop back around to this later this week. Let me know if you come up with anything in the meantime.

As for the original issue - I am not sure we have a bug or any obvious actionable work to be done in the Cypress code base? Should we leave this open (which would imply we have a bug to fix) or would you be happy to close it (but continue the discussion)?

0reactions
kasbahcommented, Jun 23, 2022

Hey, it is the right code base indeed. It can currently take 3 seconds to register with the page which is why you aren’t getting to the right page. You need to wait just over 3 seconds before clicking the button.

I realise that the way this extension currently works has some problems and is not the best way to achieve the desired behavior. This will be fixed in a re-write. It’s part of why I’d like to have some e2e tests for the extension: to help with the re-write.

Unfortunately, in addition to all the e2e frameworks that I’ve tried not being that well set up to test extensions yet, I’ve hit another road block: in interacting with the external site during tests (mouser.com) we sometimes get flagged as a bot and get blocked. puppeteer-extra-plugin-stealth seems to be the best low-effort way to try and avoid this, but that means I need to use puppeteer I guess. I might have to give up on the idea of using e2e testing for this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript: chrome extension's content_scripts message event ...
See Chrome's Docs. First, you should give your extension permission to message in your manifest: "externally_connectable": { "matches": ...
Read more >
Window: message event - Web APIs - MDN Web Docs - Mozilla
This event is not cancellable and does not bubble. Syntax. Use the event name in methods like addEventListener() , or set an event...
Read more >
chrome.events - Chrome Developers
An Event is an object that allows you to be notified when something interesting happens. Here's an example of using the chrome.alarms.
Read more >
Handling Events :: Eloquent JavaScript
Events and DOM nodes. Each browser event handler is registered in a context. In the previous example we called addEventListener on the window...
Read more >
Page: DOMContentLoaded, load, beforeunload, unload
DOMContentLoaded – the browser fully loaded HTML, and the DOM tree is built, but external resources like pictures <img> and stylesheets may not...
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