Page 1 of 1

Load an url on an existing browser immediatly after creation

PostPosted: Mon Dec 10, 2012 7:58 am
by Dublanc
Is there any way to do that ?

{
...
CefBrowser::CreateBrowser(info, static_cast< CefRefPtr<CefClient> >(this), "about:blank", browserSettings);
GetBrowser()->GetMainFrame()->LoadURL("http://www.google.fr"):
...
}

Or find a way to wait until "about:blank" is created, CreateBrowserSync doesn't work

Thanks

Re: Load an url on an existing browser immediatly after crea

PostPosted: Mon Dec 10, 2012 9:46 am
by magreenblatt
Why not pass the URL to CreateBrowser instead of "about:blank"?

Re: Load an url on an existing browser immediatly after crea

PostPosted: Tue Dec 11, 2012 5:09 am
by Dublanc
The code above is just a summary, it's just when i create a browser i can't know immediatly what url will be link with it. So i need to wait until "about:blank" is created. Is there any way/flag to know when the brower is ready to accept a new url ?

Re: Load an url on an existing browser immediatly after crea

PostPosted: Tue Dec 11, 2012 5:14 am
by magreenblatt
You could call LoadURL() from CefLifeSpanHandler::OnAfterCreated().

Re: Load an url on an existing browser immediatly after crea

PostPosted: Tue Dec 11, 2012 7:29 am
by Dublanc
Works fine !

Thanks !

Re: Load an url on an existing browser immediatly after crea

PostPosted: Fri Jul 03, 2020 7:37 am
by mmarczell
The above solution (admittedly 8 years old) doesn't seem to work in the version we're using (v83).
This is the sequence of events I'm observing:
1. I call CreateBrowser from the main thread with URL A
2. I call LoadURL from OnAfterCreated with URL B
3. OnBeforeBrowse is called with URL B
4. OnBeforeBrowse is called with URL A
5. CEF appears showing URL A

My usecase would be: (on a Mac)
- The app is not running
- The user drags a file onto the app
- NSApplication and the app delegate is created. This calls CreateBrowser with URL A (default starting screen for the app)
- application:openFile: is called on the app delegate. In here I save URL B (that would show the content of the opened file) somewhere to be opened later
- OnAfterCreated would be the opportunity to override what URL we show on start.

Re: Load an url on an existing browser immediatly after crea

PostPosted: Fri Jul 03, 2020 10:49 am
by magreenblatt
If you wish to navigate from OnAfterCreated you should create the browser with an empty URL parameter.