Page 1 of 1
Resolution parameters in CEF3
Posted: Sat Jul 04, 2020 8:12 am
by andreykrasnodar
Hello again.
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>
shows my real screen resolution. But I want to change theese parameters. Is it possible?
Re: Resolution parameters in CEF3
Posted: Sat Jul 04, 2020 11:25 am
by dilfich
Possible, but only OSR version.
SimpleOSRBrowser
GetScreenInfo( You can set the screen resolution
GetViewRect( You can set the browser resolution
Re: Resolution parameters in CEF3
Posted: Sun Jul 05, 2020 10:27 am
by andreykrasnodar
Is there any way to do it without using OSR Browser?
Re: Resolution parameters in CEF3
Posted: Sun Jul 05, 2020 10:37 am
by dilfich
Like, no, I'd like that, too(
Re: Resolution parameters in CEF3
Posted: Sun Jul 05, 2020 12:18 pm
by andreykrasnodar
I made one thing
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;
If you open website containing
Code: Select all
<script>document.write(screen.width)</script>
you will see your real screen width. But if you open a website containing
Code: Select all
<script src="script.js"></script>
and script.js is
you 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.
Re: Resolution parameters in CEF3
Posted: Sun Jul 05, 2020 12:26 pm
by dilfich
you 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.
It seems to work -
https://browserleaks.com/javascript
But this is for the screen, and for the browser how?
Re: Resolution parameters in CEF3
Posted: Sun Jul 05, 2020 4:14 pm
by andreykrasnodar
dilfich wrote: ↑Sun Jul 05, 2020 12:26 pm
you 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.
It seems to work -
https://browserleaks.com/javascript
But this is for the screen, and for the browser how?
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.
But... link below also shows parameters availWidth and availHeight which I should correct.