# browser.runtime.sendMessage() vs. browser.runtime.getBackgroundPage()

**URL:** <https://discourse.mozilla.org/t/browser-runtime-sendmessage-vs-browser-runtime-getbackgroundpage/110733>\
**Category:** Development\
**Created:** [February 5, 2023, 5:31am UTC](https://discourse.mozilla.org/t/browser-runtime-sendmessage-vs-browser-runtime-getbackgroundpage/110733 "2023-02-05T05:31:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aecreations](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/aecreations/32/30593_2.png) [@aecreations](https://discourse.mozilla.org/u/aecreations)\
**Post date:** [February 5, 2023, 5:31am UTC](https://discourse.mozilla.org/t/browser-runtime-sendmessage-vs-browser-runtime-getbackgroundpage/110733/1 "2023-02-05T05:31:57Z")

</div>

From what I tell, there are two ways that extension pages that open in popup windows (or in a new browser tab) can communicate with the background script: 1) sending messages using `browser.runtime.sendMessage()`; or, 2) calling `browser.runtime.getBackgroundPage()` to get a reference to the background page’s Window object, and using that to call the background script functions.

Is one of these two methods preferred or has any advantages over the other?

---

<div class="post-metadata">

**Author:** ![juraj.masiar](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/juraj.masiar/32/30587_2.png) [@juraj.masiar](https://discourse.mozilla.org/u/juraj.masiar)\
**Post date:** [February 5, 2023, 8:02am UTC](https://discourse.mozilla.org/t/browser-runtime-sendmessage-vs-browser-runtime-getbackgroundpage/110733/2 "2023-02-05T08:02:33Z")

</div>

Definitely prefer “sendMessage” (or “connect” API).

The issues with " getBackgroundPage":

- doesn’t work from Private windows
- doesn’t work from Firefox Container windows
- doesn’t work in [upcoming MV3](https://developer.chrome.com/docs/extensions/mv3/mv3-migration-checklist/#api-background-context), so if you use it today, it’s a guaranteed technical dept waiting for refactoring in the future
