Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Unable to access local files about:blank#blocked

Post Reply
axa
Posts: 13
Joined: Tue May 07, 2019 9:25 pm

Unable to access local files about:blank#blocked

Post by axa »

Hi,

I try to load a local javascript file and I receive "about:blank#blocked" error

2 Simple steps to reproduce using SimpleFMXBrowser
---------

1. in SimpleFMXBrowser app add

CreateGlobalCEFApp;

GlobalCEFApp.AllowFileAccessFromFiles:=true; // added and make no difference
GlobalCEFApp.DisableWebSecurity:=true; // added and make no difference
if GlobalCEFApp.StartMainProcess then
begin
Application.Initialize;
Application.CreateForm(TSimpleFMXBrowserFrm, SimpleFMXBrowserFrm);
Application.Run;
SimpleFMXBrowserFrm.Free;
end;

DestroyGlobalCEFApp;

---------

2. in uSimpleFMXBrowser unit

procedure TSimpleFMXBrowserFrm.GoBtnClick(Sender: TObject);
begin
FMXChromium1.LoadString('<!DOCTYPE html><html><head><script src="demo.js" onerror="alert(''demo faild'')"></script></head><body></body></html>',''); // added
// LoadURL; // commented
end;


where demo.js is an empty or not javascript file placed in the same directory with app, and chromium dll files (bin in this case)


Now run the app and click Go. At running time you will receive a javascript popup with title : "Javascript Alert - about:blank#blocked" and text "demo faild"

What settings I must use to allow the content ?
GlobalCEFApp.AllowFileAccessFromFiles:=true;
GlobalCEFApp.DisableWebSecurity:=true;
make no difference in this case

Thanks,
Pavel
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Unable to access local files about:blank#blocked

Post by salvadordf »

Those GlobalCEFApp properties add these switches internally :
  • --allow-file-access-from-files
  • --disable-web-security
You can find those switches and their meanings in this page :
https://peter.sh/experiments/chromium-c ... -switches/

--allow-file-access-from-files
By default, file:// URIs cannot read other file:// URIs. This is an override for developers who need the old behavior for testing.
--disable-web-security
Don't enforce the same-origin policy. (Used by people testing their sites.)
Try using a custom scheme to access local files. The SchemeRegistrationBrowser demo shows how to register the hello scheme to load the test.html file but you can register http or https to avoid problems.
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Unable to access local files about:blank#blocked

Post by salvadordf »

The SchemeRegistrationBrowser demo uses a custom TCefResourceHandlerOwn and it can be registered in the TForm.OnCreate or later as you can see in TSchemeRegistrationBrowserFrm.Chromium1ContextMenuCommand.

Read this page for more information about the resource handler :
https://magpcss.org/ceforum/apidocs3/pr ... ndler.html
axa
Posts: 13
Joined: Tue May 07, 2019 9:25 pm

Re: Unable to access local files about:blank#blocked

Post by axa »

Thanks for the info, I will try your proposed method but I was skeptical
because I read this old topic https://magpcss.org/ceforum/viewtopic.php?f=6&t=576 before posting the message
Maybe is working
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Unable to access local files about:blank#blocked

Post by salvadordf »

Please, download CEF4Delphi again from GitHub :
https://github.com/salvadordf/CEF4Delphi

I added some more code comments and a local JavaScript file to the SchemeRegistrationBrowser demo.

Any information about CEF older than 3 or 4 years should be taken with a pinch of salt because CEF has changed and improved a lot since then.
Post Reply