SergeGirard
SergeGirard

Reputation: 441

Why I can't display some site with TWebBrowser

I use Delphi Rio (Windows Desktop App) and need to display in a TWebBrowser some webpages. I ran into a problem with this WooCommerce site, https://merletdance.com/eshop. When I ask for this one, I can't pass the cookies dialog. I understand it's in relation with JScript and/or JQuery, but is there a way to bypass or better (some parameters of TwebBrowser) ?

[Edit] Works with Delphi 11 (Alexandria) using Edge

Upvotes: 0

Views: 303

Answers (1)

SergeGirard
SergeGirard

Reputation: 441

Found a solution, even if for my users with heterogeneous park it's not a cure-all: Embarcadero's documentation on TWebBrowser hints to edit the registry:

Supporting JavaScript Integration on Windows Platform

On Windows target platforms (WIN32 and WIN64), TWebBrowser may incorrectly display some Web pages if a Web site uses JavaScript dialog boxes, panels, and other elements for various purposes.

To work around this issue, your application should display Web pages in the IE11 edge mode using the FEATURE_BROWSER_EMULATION feature of Internet Explorer.

  1. Open the Registry Editor.
  2. Open the following key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
  3. On the Edit menu, point to New, and then click DWORD (32-bit) Value.
  4. Set the name of this new entry to your executable file name, such as MyApps.exe.
  5. Select the newly created entry, and on the Edit menu, click Modify.
  6. In the Edit dialog box that opens, do the following:
    • In the Value data text box, enter 11011
    • Under Base, select Decimal
    • Click OK to save your changes

You can also cause your application to make the above described changes when the application starts. For example, in your project, the FormCreate event handler can call the following TForm1.SetPermissions method:

procedure TForm1.FormCreate(Sender: TObject);
begin
{$IFDEF MSWINDOWS}
  SetPermissions;
{$ENDIF}
end;

{$IFDEF MSWINDOWS}
procedure TForm1.SetPermissions;

const
  cHomePath = 'SOFTWARE';
  cFeatureBrowserEmulation =
    'Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\';
  cIE11 = 11001;

var
  Reg: TRegIniFile;
  sKey: string;
begin

  sKey := ExtractFileName(ParamStr(0));
  Reg := TRegIniFile.Create(cHomePath);
  try
    if Reg.OpenKey(cFeatureBrowserEmulation, True) and
      not(TRegistry(Reg).KeyExists(sKey) and (TRegistry(Reg).ReadInteger(sKey)
      = cIE11)) then
      TRegistry(Reg).WriteInteger(sKey, cIE11);
  finally
    Reg.Free;
  end;

end;
{$ENDIF}

Note: You should make these appropriate changes to the registry before starting the application. After you start your application for the first time, close it, and then start again.

Upvotes: 0

Related Questions