From c737d7ab2237f9fb768367fd55090e870ab1c22b Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Thu, 7 Dec 2017 12:47:51 -0500 Subject: [PATCH] Fix various js problems with frame support --- qutebrowser/javascript/webelem.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/qutebrowser/javascript/webelem.js b/qutebrowser/javascript/webelem.js index f8aed2983..51005f882 100644 --- a/qutebrowser/javascript/webelem.js +++ b/qutebrowser/javascript/webelem.js @@ -55,7 +55,9 @@ window._qutebrowser.webelem = (function() { try { caret_position = elem.selectionStart; } catch (err) { - if (err.constructor.name === "DOMException" && + if ((err instanceof DOMException || + (frame !== null && + err instanceof frame.DOMException)) && err.name === "InvalidStateError") { // nothing to do, caret_position is already null } else { @@ -107,9 +109,17 @@ window._qutebrowser.webelem = (function() { // TODO How to generate a 0 object without this let frame_offset_rect = null; if (frame === null) { - frame_offset_rect = document.head.getBoundingClientRect(); + // Dummy object with zero offset + frame_offset_rect = { + "top": 0, + "right": 0, + "bottom": 0, + "left": 0, + "height": 0, + "width": 0, + }; } else { - frame_offset_rect = frame.getBoundingClientRect(); + frame_offset_rect = frame.frameElement.getBoundingClientRect(); } for (let k = 0; k < client_rects.length; ++k) { @@ -193,7 +203,7 @@ window._qutebrowser.webelem = (function() { const subelems = subelem_frames[i].document. querySelectorAll(selector); - const frame = subelem_frames[i].frameElement; + const frame = subelem_frames[i]; for (let elem_num = 0; elem_num < subelems.length; ++elem_num) { if (!only_visible || is_visible(subelems[elem_num])) { out.push(serialize_elem(subelems[elem_num], frame));