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.

Resolution parameters in CEF3

Post Reply
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Resolution parameters in CEF3

Post 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?
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Resolution parameters in CEF3

Post by dilfich »

Possible, but only OSR version.
SimpleOSRBrowser
GetScreenInfo( You can set the screen resolution
GetViewRect( You can set the browser resolution
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: Resolution parameters in CEF3

Post by andreykrasnodar »

Is there any way to do it without using OSR Browser?
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Resolution parameters in CEF3

Post by dilfich »

Like, no, I'd like that, too(
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: Resolution parameters in CEF3

Post 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

Code: Select all

document.write(screen.width)
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.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: Resolution parameters in CEF3

Post 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?
andreykrasnodar
Posts: 112
Joined: Wed Jul 01, 2020 10:22 am

Re: Resolution parameters in CEF3

Post 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.
Post Reply