John Lewis
John Lewis

Reputation: 347

Event is not getting fired

I am trying to use the WebWorkerStarted and WebWorkerFinished from TWebbrowser however the events just don't get fired at all.

How can I get these events working? I want to see which worker threads are getting launched from TWebbrowser.

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.OleCtrls, SHDocVw;

type
  TForm2 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure WebBrowser1WebWorkerFinsihed(ASender: TObject; dwUniqueID: Cardinal);
    procedure WebBrowser1WebWorkerStarted(ASender: TObject; dwUniqueID: Cardinal; const bstrWorkerLabel: WideString);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate('www.stackoverflow.com');
end;

procedure TForm2.WebBrowser1WebWorkerFinsihed(ASender: TObject; dwUniqueID: Cardinal);
begin
  // does not fire
end;

procedure TForm2.WebBrowser1WebWorkerStarted(ASender: TObject; dwUniqueID: Cardinal; const bstrWorkerLabel: WideString);
begin
  // does not fire
end;

end.

Upvotes: 2

Views: 266

Answers (1)

J...
J...

Reputation: 31393

As documented here :

By default, TWebBrowser uses IE7 Standards mode even if the run-time environment installed the latest IE (for example, IE11).

WebWorkers were introduced in IE10 so you must have IE running in a more current mode. At least two registry keys need to be set (more if supporting both 32/64 bit):

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER) 
  {\Wow6432Node}
  \SOFTWARE
  \Microsoft 
  \Internet Explorer
  \Main
  \FeatureControl
  \FEATURE_BEHAVIORS
     {NEW DWORD ->  'YourApplication.exe'
     {    VALUE -> 1  

Also (for example, IE11 mode)

  HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER) 
  {\Wow6432Node}
  \SOFTWARE
  \Microsoft 
  \Internet Explorer
  \Main
  \FeatureControl
  \FEATURE_BROWSER_EMULATION
     {NEW DWORD ->  'YourApplication.exe'
     {    VALUE ->  0x2AF8 

This will cause the internet explorer instance wraped by TWebBrowser to run in IE11 mode, supporting WebWorkers, etc. You should probably do some sort of sanity check against the installed version of IE before setting this value. More information about valid entries can be found on MSDN.

This still does not raise any WebWorker events for me when navigating to StackOverflow (are you sure it uses them?). As a verification test, this WebWorkers demo page does raise a OnWebWorkerStarted event :

WebBrowser1.Navigate('https://whatwg.org/demos/workers/primes/page.html'); 

Upvotes: 6

Related Questions