Hi,
this doesn't work for me:
Chromium1.Browser.MainFrame.ExecuteJavaScript('document.body.webkitRequestFullScreen();', Chromium1.Browser.MainFrame.GetURL, 0);
Chromium1.Browser.MainFrame.ExecuteJavaScript('document.documentElement.webkitRequestFullScreen();', Chromium1.Browser.MainFrame.GetURL, 0);
This always return "requestFullscreen' on 'Element': API can only be initiated by a user gesture". Do you have any ideas if there is a work-around, an option for CEF ...? It seems that there is an "fullscreen-enabled" option (--fullscreen-enabled), but i don't know, how to set this option.
Another idea: Send a double-click message to the browser (SendMessage(Chromium1.WindowHandle,MOUSEEVENTF_LEFTDOWN,0,0)), but this doesn't work, the youtube video isn't maximized (but doing a double click with the mouse, works fine).
Best
Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
Fullscreen by JavaScript
- salvadordf
- Posts: 4572
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Fullscreen by JavaScript
Hi,
Read this forum thread to simulate keyboard presses and mouse clicks :
https://www.briskbard.com/forum/viewtopic.php?f=8&t=969
Read this forum thread to simulate keyboard presses and mouse clicks :
https://www.briskbard.com/forum/viewtopic.php?f=8&t=969
Re: Fullscreen by JavaScript
[Edit]
Solve it, amazing! Not the finest way, but it works for me.
Solve it, amazing! Not the finest way, but it works for me.
Code: Select all
Procedure ToggleFullScreen(Browser: TChromium);
var
MouseEvent : TCefMouseEvent;
KeyEvent : TCefKeyEvent;
begin
if (Browser <> nil) then begin
MouseEvent.x := 150; // CEFWindowParent1.Width div 2;
MouseEvent.y := 150; // CEFWindowParent1.Height div 2;
Browser.Browser.Host.SendFocusEvent(true);
Browser.Browser.Host.SendMouseClickEvent(PCefMouseEvent(@MouseEvent), MBT_LEFT, false, 2);
Browser.Browser.Host.SendMouseClickEvent(PCefMouseEvent(@MouseEvent), MBT_LEFT, true, 1);
Browser.Browser.Host.SendFocusEvent(true);
end;
end;
Last edited by Det20 on Thu Nov 21, 2019 1:09 pm, edited 1 time in total.
- salvadordf
- Posts: 4572
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Fullscreen by JavaScript
I've never done that but you can log all the necessary parameters with the SimpleOSRBrowser demo.
Re: Fullscreen by JavaScript
Can i "move" the current browser (Chromium1) to another panel without recreate it? An idea is to create a borderless and fullscreen panel, move Chromium browser to this panel by, for example, just set the new parent.
- salvadordf
- Posts: 4572
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Fullscreen by JavaScript
Try TChromium.SetNewBrowserParent
Re: Fullscreen by JavaScript
Thank you, that works perfekt.
Global Variable:
With Button Click ...
And at least handle ESC in Form.KeyUp:
Global Variable:
Code: Select all
ChromiumExtPanel: TPanel;
Code: Select all
Procedure TfrmMain.FullScreenChrome(Chrome: TCEFWindowParent; SetFullscreen: Boolean);
begin
If SetFullScreen then begin
If Assigned(ChromiumExtPanel) then Exit;
// Create TempPanel
ChromiumExtPanel := TPanel.Create(nil);
ChromiumExtPanel.Left := 0;
ChromiumExtPanel.Top := 0;
ChromiumExtPanel.Width := Screen.Width;
ChromiumExtPanel.Height := Screen.Height;
ChromiumExtPanel.Parent := Self;
ChromiumExtPanel.ParentBackground := false;
ChromiumExtPanel.Color := clBlack;
ChromiumExtPanel.BevelInner := bvNone;
ChromiumExtPanel.BevelOuter := bvNone;
// Move TempPanel to outside form
SetWindowLong(ChromiumExtPanel.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
Winapi.Windows.SetParent(ChromiumExtPanel.Handle, GetDesktopWindow);
// Move Chromium to TempPanel
Winapi.Windows.SetParent(Chrome.Handle, ChromiumExtPanel.Handle);
frmMain.KeyPreview := true; // Because of ESC Key
Chrome.Align := alNone;
Chrome.Width := ChromiumExtPanel.Width-5;
Chrome.Height := ChromiumExtPanel.Height-5;
End Else begin
If (not Assigned(ChromiumExtPanel)) then Exit;
Winapi.Windows.SetParent(Chrome.Handle, ....Handle); // Old Parent
frmMain.KeyPreview := false; // Because of ESC Key
Chrome.Align := alClient;
FreeAndNil(ChromiumExtPanel);
End;
end;
Code: Select all
procedure TfrmMain.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
If (Key=VK_ESCAPE) and Assigned(ChromiumExtPanel) then FullScreenChrome(...,false);
end;