{"id":16453437,"url":"https://github.com/blimmer/firefox-sendmessage-response-example","last_synced_at":"2025-02-26T20:42:21.206Z","repository":{"id":145468999,"uuid":"305461432","full_name":"blimmer/firefox-sendmessage-response-example","owner":"blimmer","description":null,"archived":false,"fork":false,"pushed_at":"2020-10-19T17:26:41.000Z","size":142,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-09T13:57:49.331Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/blimmer.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":"2020-10-19T17:25:43.000Z","updated_at":"2020-10-19T17:26:43.000Z","dependencies_parsed_at":"2023-04-04T05:14:31.542Z","dependency_job_id":null,"html_url":"https://github.com/blimmer/firefox-sendmessage-response-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Ffirefox-sendmessage-response-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Ffirefox-sendmessage-response-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Ffirefox-sendmessage-response-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blimmer%2Ffirefox-sendmessage-response-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blimmer","download_url":"https://codeload.github.com/blimmer/firefox-sendmessage-response-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240934407,"owners_count":19880991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-10-11T10:15:37.596Z","updated_at":"2025-02-26T20:42:21.175Z","avatar_url":"https://github.com/blimmer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Firefox / Chrome `sendMessage` response incompatibility\n\nThis is a simple example showing a difference between Firefox and Google Chrome's `sendMessage` response behaviors. I\ncame across this issue when migrating a Chrome Extension over to Firefox.\n\n## Background\n\nIn this sample code, I'm using [Vuex](https://vuex.vuejs.org/) in my Background Script as a data store. Vuex wraps\nbasic Javascript objects with reactive getters and setters, which exposes the problem. So, when a plain ol' Javascript\nobject is defined in the Vuex Store's `state`, it is automatically transformed.\n\nIn this example (see [`bg.js`](bg.js)), `myObj` in the `state` is defined like this:\n\n```js\nconst store = new Vuex.Store({\n  state: {\n    myObj: {\n      foo: 'bar'\n    },\n  },\n});\n```\n\nIf you inspect the object fetched from the store (`store.state.myObj`), you'll see the `foo` property is automatically\nwrapped with `reactiveGetter` and `reactiveSetter`.\n\n![screenshot showing wrapped properties](images/wrapped.png)\n\n## The Issue\n\nThe difference between Firefox and Google Chrome is exposed when a Vuex object is pulled from `state` and sent as a\nresponse to a `sendMessage` call from a Content Script (see [`bg.js`](bg.js) and [`cs.js`](cs.js)).\n\n### Firefox\n\nOn Firefox, the response is an empty object with no properties.\n\n![screenshot showing empty object on firefox](images/firefox.png)\n\n### Google Chrome\n\nOn Google Chrome, the response contains the expected property (though the `getters` and `setters` are removed).\n\n![screenshot showing object on chrome](images/chrome.png)\n\n## Using This Repository\n\nTo use this repository to reproduce the problem:\n\n1. Clone this repository.\n\n1. Load up the `manifest.json` as a temporary addon in Firefox or as a Developer Extension in Google Chrome.\n\n1. Visit [https://developer.mozilla.org/en-US/](https://developer.mozilla.org/en-US/).\n\n1. Open the Javascript console. The contents of the `sendMessage` response are logged using `console.dir`.\n\nNote that Google Chrome has the `foo` property defined in the response, while Firefox does not.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblimmer%2Ffirefox-sendmessage-response-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblimmer%2Ffirefox-sendmessage-response-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblimmer%2Ffirefox-sendmessage-response-example/lists"}