Search code examples
delphichromiumchromium-embeddedtwebbrowser

Get, a good encoded URL for TChromium


Whith TWebBrowser based on Internet Explorer the URL is not encrypted, for example i can simply go :

path:='file:///C:/##Project/Page.html
WebBrowser1.Navigate(path);

But, for TChromium Component URL is encoded like :

path:='file:///D:/%23%23Project/Page.html
chrm1.Browser.MainFrame.LoadUrl(path);

This is a problem because in the program I create the path (URL) using :

path := ExtractFilePath(Application.ExeName)+ 'Page.html';

And chromium does not recognize the path, because it is not properly encoded.


Solution

  • Update:

    I installed DCEF3 and the following works fine for that specific path in the GuiClient demo:

      Path := StringReplace(Path, '#', '%23', [rfReplaceAll]);
      crm.Browser.MainFrame.LoadUrl(Path);
    

    I also tried

    Path := TIdURI.UrlEncode(Path);
    

    but that left the Path value unchanged (in D7). So, for a more general solution than my StringReplace one, you might want to take a look at some of the answers in the q Hugh Jones gave a link to,

    stackoverflow.com/questions/776302/standard-url-encode-function

    [Original]

    I don't have DCEF3 installed to check, but it look like you need to do

    path := ExtractFilePath(Application.ExeName)+ 'Page.html';
    path := HttpEncode(Path);
    chrm1.Browser.MainFrame.LoadUrl(path);
    

    after adding HttpApp to your Uses.