Disable CORS
Posted: Wed May 04, 2022 7:25 am
Is it possible to disable the domain name matching check?
"strict-origin-when-cross-origin"
"strict-origin-when-cross-origin"
The forum for BriskBard users and CEF4Delphi / WebView4Delphi / WebUI4Delphi / WebUI4CSharp developers
https://www.briskbard.com/forum/
Code: Select all
TempArgs := TCoreWebView2FrameCreatedEventArgs.Create(aArgs);
Code: Select all
TempFrame := TCoreWebView2Frame.Create(TempArgs.Frame);
Code: Select all
TempFrame.ExecuteScript(MyJavaScriptCode, MyCustonID, WVBrowser1);
salvadordf wrote: Wed May 04, 2022 7:02 pm Executing JavaScript in a frame is possible but not as easy as in CEF.
Follow these steps :
- Use the TWVBrowserBase.OnFrameCreated event.
- Create a TCoreWebView2FrameCreatedEventArgs instance with the aArgs parameter like this :
Code: Select all
TempArgs := TCoreWebView2FrameCreatedEventArgs.Create(aArgs);
- Create a TCoreWebView2Frame instance like this :
Code: Select all
TempFrame := TCoreWebView2Frame.Create(TempArgs.Frame);
- Call the TCoreWebView2Frame.ExecuteScript procedure like this :
Code: Select all
TempFrame.ExecuteScript(MyJavaScriptCode, MyCustonID, WVBrowser1);
- WVBrowser1.OnExecuteScriptCompleted will be triggered when the execution is complete.
Code: Select all
TempFrame.ExecuteScript(MyJavaScriptCode, MyCustonID, WVBrowser1);
Code: Select all
var
G_TempFrame: ICoreWebView2Frame;
procedure TForm1.WVBrowser1FrameCreated(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2FrameCreatedEventArgs);
var
nameFrame: PWideChar;
begin
G_TempArgs := ICoreWebView2FrameCreatedEventArgs(aArgs);
aArgs.Get_Frame(G_TempFrame);
G_TempFrame.Get_name(nameFrame);
G_TempFrame.ExecuteScript(MyJavaScriptCode, MyCustonID, WVBrowser1); <=== ERROR
Form1.Memo1.Lines.Add('irame' + nameFrame);
end;
Could you give an example in my code? I think I don't have enough experience, I can't call TCoreWebView2Frame - this method is unknown to me in the IDE. Thank you for your help!salvadordf wrote: Mon May 09, 2022 8:06 am ExecuteScript is declared by ICoreWebView2Frame2.
Create a TCoreWebView2Frame class or use aArgs.QueryInterface(ICoreWebView2Frame2, G_TempFrame) if you decide to declare G_TempFrame as ICoreWebView2Frame2.
Code: Select all
procedure TMainForm.WVBrowser1ExecuteScriptCompleted(Sender: TObject;
aErrorCode: HRESULT; const aResultObjectAsJson: wvstring;
aExecutionID: Integer);
begin
if aExecutionID = 42 then
begin
// MyJavaScriptCode finished executing
end;
end;
procedure TMainForm.WVBrowser1FrameCreated(Sender: TObject;
const aWebView: ICoreWebView2;
const aArgs: ICoreWebView2FrameCreatedEventArgs);
var
TempArgs : TCoreWebView2FrameCreatedEventArgs;
TempFrame : TCoreWebView2Frame;
MyJavaScriptCode : wvstring;
MyCustonID : integer;
begin
TempArgs := TCoreWebView2FrameCreatedEventArgs.Create(aArgs);
TempFrame := TCoreWebView2Frame.Create(TempArgs.Frame);
MyJavaScriptCode := 'your JS code goes here';
MyCustonID := 42; // Use any value. This is only used to keep track of the executed JS code in WVBrowser1ExecuteScriptCompleted
TempFrame.ExecuteScript(MyJavaScriptCode, MyCustonID, WVBrowser1);
TempFrame.Free;
TempArgs.Free;
end;
salvadordf wrote: Tue May 10, 2022 8:47 amCode: Select all
procedure TMainForm.WVBrowser1ExecuteScriptCompleted(Sender: TObject; aErrorCode: HRESULT; const aResultObjectAsJson: wvstring; aExecutionID: Integer); begin if aExecutionID = 42 then begin // MyJavaScriptCode finished executing end; end; procedure TMainForm.WVBrowser1FrameCreated(Sender: TObject; const aWebView: ICoreWebView2; const aArgs: ICoreWebView2FrameCreatedEventArgs); var TempArgs : TCoreWebView2FrameCreatedEventArgs; TempFrame : TCoreWebView2Frame; MyJavaScriptCode : wvstring; MyCustonID : integer; begin TempArgs := TCoreWebView2FrameCreatedEventArgs.Create(aArgs); TempFrame := TCoreWebView2Frame.Create(TempArgs.Frame); MyJavaScriptCode := 'your JS code goes here'; MyCustonID := 42; // Use any value. This is only used to keep track of the executed JS code in WVBrowser1ExecuteScriptCompleted TempFrame.ExecuteScript(MyJavaScriptCode, MyCustonID, WVBrowser1); TempFrame.Free; TempArgs.Free; end;
Code: Select all
uses
uWVCoreWebView2Frame, uWVCoreWebView2Args