From acf09d2285b47d5849b4315ac698182dad7e9c13 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Sun, 28 Oct 2018 11:45:14 +0800 Subject: use Shadow DOM v1 if it exists Chrome 70 has deprecated Shadow DOM v0 and displayed a warning when it's used. And accroding to https://www.chromestatus.com/features/4507242028072960, Shadow DOM v0 will be removed since Chrome 73. The support for Shadow DOM v1 has been there since Chrome 53 and is enabled by default on Firefox 63, so it's time to use it. Old support is still needed because Vimium's min_chrome_version is 51. --- content_scripts/ui_component.coffee | 2 +- content_scripts/vimium_frontend.coffee | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index c71bfb35..f0815d08 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -27,7 +27,7 @@ class UIComponent seamless: "seamless" shadowWrapper = DomUtils.createElement "div" # PhantomJS doesn't support createShadowRoot, so guard against its non-existance. - @shadowDOM = shadowWrapper.createShadowRoot?() ? shadowWrapper + @shadowDOM = shadowWrapper.attachShadow?() ? shadowWrapper.createShadowRoot?() ? shadowWrapper @shadowDOM.appendChild styleSheet @shadowDOM.appendChild @iframeElement @toggleIframeElementClasses "vimiumUIComponentVisible", "vimiumUIComponentHidden" diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index ff27c8a4..2eb4a0cd 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -245,7 +245,10 @@ flashFrame = do -> # Create a shadow DOM wrapping the frame so the page's styles don't interfere with ours. highlightedFrameElement = DomUtils.createElement "div" # PhantomJS doesn't support createShadowRoot, so guard against its non-existance. - _shadowDOM = highlightedFrameElement.createShadowRoot?() ? highlightedFrameElement + # https://hacks.mozilla.org/2018/10/firefox-63-tricks-and-treats/ says + # Firefox 63 has enabled Shadow DOM v1 by default + _shadowDOM = highlightedFrameElement.attachShadow?() ? + highlightedFrameElement.createShadowRoot?() ? highlightedFrameElement # Inject stylesheet. _styleSheet = DomUtils.createElement "style" -- cgit v1.2.3 From 5307f07729f2a35debbee6ef8c5f09493a8b81bf Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Sun, 28 Oct 2018 11:53:27 +0800 Subject: fix a small typo that attachShadow needs an argument --- content_scripts/ui_component.coffee | 3 ++- content_scripts/vimium_frontend.coffee | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index f0815d08..d3145eb3 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -27,7 +27,8 @@ class UIComponent seamless: "seamless" shadowWrapper = DomUtils.createElement "div" # PhantomJS doesn't support createShadowRoot, so guard against its non-existance. - @shadowDOM = shadowWrapper.attachShadow?() ? shadowWrapper.createShadowRoot?() ? shadowWrapper + @shadowDOM = shadowWrapper.attachShadow?( mode: "open" ) ? + shadowWrapper.createShadowRoot?() ? shadowWrapper @shadowDOM.appendChild styleSheet @shadowDOM.appendChild @iframeElement @toggleIframeElementClasses "vimiumUIComponentVisible", "vimiumUIComponentHidden" diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 2eb4a0cd..0f5d05f2 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -247,7 +247,7 @@ flashFrame = do -> # PhantomJS doesn't support createShadowRoot, so guard against its non-existance. # https://hacks.mozilla.org/2018/10/firefox-63-tricks-and-treats/ says # Firefox 63 has enabled Shadow DOM v1 by default - _shadowDOM = highlightedFrameElement.attachShadow?() ? + _shadowDOM = highlightedFrameElement.attachShadow?( mode: "open" ) ? highlightedFrameElement.createShadowRoot?() ? highlightedFrameElement # Inject stylesheet. -- cgit v1.2.3