OLD | NEW |
1 (function() { | 1 (function() { |
2 | 2 |
3 // Gets the offset of an element in coordinates relative to the top-level frame. | 3 // Gets the offset of an element in coordinates relative to the top-level frame. |
4 function offset(element) { | 4 function offset(element) { |
5 const rect = element.getBoundingClientRect(); | 5 const rect = element.getBoundingClientRect(); |
6 const iframe = element.ownerDocument.defaultView.frameElement; | 6 const iframe = element.ownerDocument.defaultView.frameElement; |
7 if (!iframe) { | 7 if (!iframe) { |
8 return { left: rect.left, top: rect.top }; | 8 return { left: rect.left, top: rect.top }; |
9 } | 9 } |
10 const outerOffset = offset(iframe); | 10 const outerOffset = offset(iframe); |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 function observe(target) { | 38 function observe(target) { |
39 observer.observe(target, { childList: true, subtree: true }); | 39 observer.observe(target, { childList: true, subtree: true }); |
40 } | 40 } |
41 | 41 |
42 // Handle what's already in the document. | 42 // Handle what's already in the document. |
43 for (const button of document.getElementsByTagName('button')) { | 43 for (const button of document.getElementsByTagName('button')) { |
44 click(button); | 44 click(button); |
45 } | 45 } |
46 for (const iframe of document.getElementsByTagName('iframe')) { | 46 for (const iframe of document.getElementsByTagName('iframe')) { |
47 observe(iframe.contentDocument); | 47 try { |
48 iframe.addEventListener('load', () => { | |
49 observe(iframe.contentDocument); | 48 observe(iframe.contentDocument); |
50 }); | 49 iframe.addEventListener('load', () => { |
| 50 observe(iframe.contentDocument); |
| 51 }); |
| 52 } catch (e) { |
| 53 // Skip cross-origin iframes, but report other errors |
| 54 if (e.name != "SecurityError") { |
| 55 throw e; |
| 56 } |
| 57 } |
51 } | 58 } |
52 | 59 |
53 // Observe future changes. | 60 // Observe future changes. |
54 observe(document); | 61 observe(document); |
55 | 62 |
56 })(); | 63 })(); |
OLD | NEW |