Page 1 of 1

Unable to access local files about:blank#blocked

Posted: Sat May 11, 2019 5:50 pm
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

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

Posted: Sat May 11, 2019 6:20 pm
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.

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

Posted: Sat May 11, 2019 6:27 pm
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

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

Posted: Sun May 12, 2019 1:29 am
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

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

Posted: Sun May 12, 2019 8:57 am
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.