aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dom_utils.coffee4
-rw-r--r--lib/utils.coffee8
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index c21d5a29..d0bd4615 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -5,7 +5,7 @@ DomUtils =
documentReady: do ->
[isReady, callbacks] = [document.readyState != "loading", []]
unless isReady
- window.addEventListener "DOMContentLoaded", onDOMContentLoaded = ->
+ window.addEventListener "DOMContentLoaded", onDOMContentLoaded = forTrusted ->
window.removeEventListener "DOMContentLoaded", onDOMContentLoaded
isReady = true
callback() for callback in callbacks
@@ -16,7 +16,7 @@ DomUtils =
documentComplete: do ->
[isComplete, callbacks] = [document.readyState == "complete", []]
unless isComplete
- window.addEventListener "load", onLoad = ->
+ window.addEventListener "load", onLoad = forTrusted ->
window.removeEventListener "load", onLoad
isComplete = true
callback() for callback in callbacks
diff --git a/lib/utils.coffee b/lib/utils.coffee
index babb5f96..78eed12c 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -1,3 +1,11 @@
+# Only pass events to the handler if they are marked as trusted by the browser.
+# This is kept in the global namespace for brevity and ease of use.
+window.forTrusted ?= (handler) -> (event) ->
+ if event?.isTrusted
+ handler.apply this, arguments
+ else
+ true
+
Utils =
getCurrentVersion: ->
chrome.runtime.getManifest().version