3

For utilising content script advantages, I tried writing html code inside my chrome extension and tried injecting it into a created iframe using content script. It actually works, however it seems blurry (I have tried --webkit-font-smoothing: antialiased - and also if I go to the direct URL of the html page inside the extension (http://chrome-extension://ext_id/views/my_html.html), it doesn't get blurred on the actual html).

var elt = document.createElement('iframe');
elt.id = 'my_iframe';
elt.src = chrome.extension.getURL('views/my_iframe.html')
elt.setAttribute('scrolling', 'no');
document.getElementsByTagName('body')[0].appendChild(elt);

This is the approach I used. And again, if I go to http://chrome-extension://ext_id/views/my_html.html it doesn't get blurry (please check image at the bottom).


So I started investigating what may be causing the issue. First, I tried to inject live websites into the iframe through src attribute, and they don't get blurry:

elt.src = "https://example.com"

However, here, one thing I realised for iframe is that all the other URLs that I fetch seem like this in the Inspect Element.

The iframe element is openable and it has #document as child which has all the html content as grandchildren

enter image description here

However, my one looks like this on the DOM that it doesn't open and I don't have #document tag either.

enter image description here


Second thing I tried was getting the content of the html page using

$.get(chrome.extension.getURL('views/my_html.html'), function(data, status){
    // and inject data inside the iframe, however that 
    // caused path errors of separated files such as css and js..
});

.. because in my html file, I included files as

<link href="/styles/my_css.css" rel="stylesheet" type="text/css">
<script src="/libs/jquery-3.2.1.min.js"></script>

Thirdly, I tried zooming on the page to see what's happening. When I zoom, it gets blurry and very interestingly, if I open Inspect Element, it gets zoomed it also which doesn't on any iframe or any other website. It seems like I have injected a JPEG image in the iframe; and even inspect element gets blurry inside the iframe

enter image description here

enter image description here

If I inject any website into my iframe, even if I zoom in 1) Inspect Element doesn't get magnified, 2) Even if I zoom, it doesn't get pixelated or blurry simply because it's code; however in my case, it's acting like an image.

enter image description here

It's driving me insane how and why this is happening. Do you have any ideas thoughts what may be causing it or how to overcome this issue?


For recreating the issue, you can follow this method

Also, I have created a simplified extension for replicating the issue: https://drive.google.com/open?id=1y0Dopp1GhU47tWhXgxoGUy3DaDsQDouc

Even an almost empty project, it's blurry:

enter image description here

However it doesn't on webpage URL to the same html

enter image description here

senty
  • 12,385
  • 28
  • 130
  • 260
  • I don't **know** if anything like this would work, but have you tried anything like `-webkit-font-smoothing`? Maybe that's not being included in the iframe? - I'm trying to help but to be fair, this question has made me question why this happens... – JO3-W3B-D3V Mar 28 '18 at 08:56
  • @JO3-W3B-D3V Yes, I tried `-webkit-font-smoothing: antialiased;` but no luck. Also, as I said, if I go to the real path of the extension html, it is very smooth, even if I zoom in. It only looks blurry in the iframe – senty Mar 28 '18 at 08:58
  • Interesting.... Hmmm... I have a gut feeling it's down to the way the browser implements the iframe... But I don't know, I mean you could always create your own JS solution to simulate an iframe? Maybe that could be a better solution? - Obviously it would take time, and it wouldn't answer your question, but it's a work around to say the least. – JO3-W3B-D3V Mar 28 '18 at 09:01
  • Here I have created a [simple demo project](https://drive.google.com/open?id=1y0Dopp1GhU47tWhXgxoGUy3DaDsQDouc) for showing the issue. You can check too, it's very surprising! Also, what do you mean by "simulate an iframe"? – senty Mar 28 '18 at 09:08
  • Sounds like a bug in Chrome. See if it's fixed in Chrome Canary, otherwise report on https://crbug.com – wOxxOm Mar 28 '18 at 09:28
  • @wOxxOm yes, the issue exists in Chrome Canary too. Submitted the bug report :( – senty Mar 28 '18 at 09:32
  • @senty I mean make some element that's nxn size, and load another page through ajax/xhr into this element... Do you think you could work with that? It was just an idea, doesn't mean it was a good one, lol... – JO3-W3B-D3V Mar 28 '18 at 10:03
  • 1
    @JO3-W3B-D3V ye, probably not as convenient as iframe approach. – senty Mar 28 '18 at 10:16
  • @senty without a doubt not as convenient.. That's why I said in my last response how it's a work around... I appreciate it's not the ideal solution, but it wouldn't be that hard to replicate.. – JO3-W3B-D3V Mar 28 '18 at 10:27
  • I'm also having this issue, did you figure out a way to fix this issue? – Coder Guy Jun 24 '20 at 00:06
  • For others who are facing the issue, you can star bug here: [https://bugs.chromium.org/p/chromium/issues/detail?id=826646&q=blur%20iframe%20extension&can=2](https://bugs.chromium.org/p/chromium/issues/detail?id=826646&q=blur%20iframe%20extension&can=2) – Snehal Baghel Feb 24 '21 at 07:54
  • Did anyone find a solution for this? – Yontzzi Oct 18 '21 at 05:38

0 Answers0