I use Selenium Webdriver in a python script to download sites from my webpage and convert them into PNGs:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
options = Options()
options.headless = False
SITE = "http://localhost/something_I_want_to_convert_with_hi-resolution.html"
DPI = 2.5
profile = webdriver.FirefoxProfile()
profile.set_preference("layout.css.devPixelsPerPx", str(DPI))
driver = webdriver.Firefox(options=options, firefox_profile=profile)
driver.get(SITE)
...
This worked fine until last month when I still used Ubuntu 20.04. It created the images with the right font like this.
I guess exactly since the Ubuntu upgrade Firefox cannot load the custom fonts, I have included via css in my site, anymore and it loads the default fonts instead now.
What could have changed that behaviour? Was there a recent update in Ubuntu 20.10 that changed the behaviour of Firefox?
I get this error in the console which is strange:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/css/fonts/kramer__.TTF. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
it is strange, because the font is in the same domain (localhost
) so there shouldn't be a CORS error.
The same site works fine in Chrome and loads the fonts. Also in Waterfox-classic it loads the fonts just fine.
I would like to add something like:
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
but I serve the site locally with ZeroNet, which is html-, CSS- and JS-only, so I think, I cannot change the headers sent.
I tried in firefox about:config
:
- disable
content.cors.disable
(empty string) security.fileuri.strict_origin_policy
Falseprivacy.file_unique_origin
False
but none of those had any effect.
If I install the access-control-allow-origin addon and enable Access-Control-Allow-Origin: *
it also works fine, (I added that as a workaround below.)
How do I set Firefox to ignore the Cross-Origin Request?