Javascript Global Variable for Cef Extension Scripts

Discussion of current events and participation in intelligent conversation with other CEF users.

Javascript Global Variable for Cef Extension Scripts

Postby thekilic » Thu Mar 03, 2016 7:08 am

First of all, I have searched in gitter and github discussion boards and wiki pages but still has no move..

So I ask the question for the first time here.....:

The last and may be the best thing is I tried that exposing an object to javascript scope. https://github.com/cefsharp/CefSharp/wi ... ose_dotNET

Okay this is working for string type objects. But I have a complex object that has several string arrays inside.

I want to keep javascript variable , lets call it var _myFilters values during the browsers lifecycle.

I know about cef extensions, there I remember this sentence:
Extensions Extensions are like window bindings except they are loaded into the context for every frame and cannot be modified once loaded. The DOM does not exist when an extension is loaded and attempts to access the DOM during extension loading will result in a crash. Extensions are registered using the CefRegisterExtension() function which should be called from the CefRenderProcessHandler::OnWebKitInitialized() method.
quoting from a website :https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration

So I see this the best place where I can create my global javascript variable "_myFilters". It should be accesible in each browser tab, but I tried it , and saw it ( refer: " _myFilters " ) looses value on each time page reloads.

Registering the object is an option but it does not fit well to my complex javascript object (_myFilters) ..

Code: Select all
browser.RegisterJsObject("bound", new BoundObject());

This I tried but only worked well for string, int etc.

I am planning to expose an "object" (refer: _myFilters) data type but this time, the browser crashes.

So the question is that:, what is the best way to have a global variable to be used in the files that are executing javascript files on browser loadstart, load end, on beforebrowse methods.. ?

ps: I want this because, creating this _myFilters object is a job that takes some time (about 3 seconds). I want to have its values in my global value, so I can use it during browsers life cycle.

ps2: The type of _myFilters
Image
thekilic
Newbie
 
Posts: 2
Joined: Thu Mar 03, 2016 6:52 am

Re: Javascript Global Variable for Cef Extension Scripts

Postby magreenblatt » Thu Mar 03, 2016 1:40 pm

It sounds like you're using CefSharp. You should ask your question on a forum specific to that project.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Javascript Global Variable for Cef Extension Scripts

Postby thekilic » Thu Mar 03, 2016 5:18 pm

Okay, so simple question: Is this possible?
in cef, can we have a global variable if we define it and register it as cef extension?
thekilic
Newbie
 
Posts: 2
Joined: Thu Mar 03, 2016 6:52 am

Re: Javascript Global Variable for Cef Extension Scripts

Postby magreenblatt » Thu Mar 03, 2016 5:22 pm

thekilic wrote:in cef, can we have a global variable if we define it and register it as cef extension?

No. Global variables are attached to the window object, and the window object does not exist when an extension is loaded. In C++ you would use CefRenderProcessHandler::OnContextCreated instead.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 13 guests