I am using CEF 3 and need an unusual function
Just simple JavaScript code
Code: Select all
<script>
document.write(screen.width);
document.write(screen.height);
</script>
Code: Select all
<script>
document.write(screen.width);
document.write(screen.height);
</script>
Code: Select all
procedure TForm1.Chromium1BeforeResourceLoad(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; const callback: ICefRequestCallback;
out Result: TCefReturnValue);
var
CodeStr:string;
screenwidth, screenheight: integer;
begin
screenwidth:=800;
screenheight:=600;
CodeStr:='';
CodeStr:=CodeStr+'var tempScreen = {}; for (var obj in screen)tempScreen[obj] = screen[obj]; tempScreen.__proto__ = screen.__proto__; screen = tempScreen;screen.width = '+IntToStr(screenwidth)+';screen.height = '+IntToStr(screenheight)+';';
Chromium1.Browser.MainFrame.ExecuteJavaScript(CodeStr, 'about:blank', 0);
end;
Code: Select all
<script>document.write(screen.width)</script>
Code: Select all
<script src="script.js"></script>
Code: Select all
document.write(screen.width)
It seems to work - https://browserleaks.com/javascriptyou will see 800
but if you reload this page (browser will load script from the cache, I think) you will see your real width.
Fun.
The browser window (in my project) is more simple: just set Chromium component parameters width and height as needed screen width and screen height minus constant.dilfich wrote: Sun Jul 05, 2020 12:26 pmIt seems to work - https://browserleaks.com/javascriptyou will see 800
but if you reload this page (browser will load script from the cache, I think) you will see your real width.
Fun.
But this is for the screen, and for the browser how?