From e0bbc1370abe6d27b78745ce87983055ba1bfdc3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 15 Aug 2017 13:45:09 +0100 Subject: Fix search completion (Firefox). The problem is that Firefox balks at function properties within the response sent via `postMessage` (whereas Chrome does not). A concise and safe way to sanitize the response is to convert it to JSON and back. Fixes #2576. --- background_scripts/main.coffee | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 6c9fbc98..15292ab6 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -50,6 +50,10 @@ completers = completionHandlers = filter: (completer, request, port) -> completer.filter request, (response) -> + # NOTE(smblott): response contains `relevancyFunction` (function) properties which cause postMessage, + # below, to fail in Firefox. See #2576. We cannot simply delete these methods, as they're needed + # elsewhere. Converting the response to JSON and back is a quick and easy way to sanitize the object. + response = JSON.parse JSON.stringify response # We use try here because this may fail if the sender has already navigated away from the original page. # This can happen, for example, when posting completion suggestions from the SearchEngineCompleter # (which is done asynchronously). -- cgit v1.2.3