intercepting arbitrary javascript function calls

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

intercepting arbitrary javascript function calls

Postby mrp » Mon Nov 03, 2014 2:15 pm

Sorry if this has been answered previously. I did search but nothing showed up.

I am wondering how I can intercept arbitrary javascript function calls in CEF, not just the ones bound to the window object. What I am looking for is a way to intercept js calls and modify their behavior on the native side.

Thanks,
mrp
mrp
Newbie
 
Posts: 5
Joined: Mon Nov 03, 2014 1:43 pm

Re: intercepting arbitrary javascript function calls

Postby magreenblatt » Mon Nov 03, 2014 7:35 pm

In JavaScript you can modify the prototype of standard objects to call your method instead.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: intercepting arbitrary javascript function calls

Postby mrp » Tue Nov 04, 2014 12:48 am

Can you explain how that can be done in the render process? To be clear, I am calling a function, say foo() as soon as the DOM is loaded (from jQuery's $(document.ready()). But I want to intercept the call to "foo" from C++ native and call bar() javascript function instead. How can I do that?

Thanks.
mrp
Newbie
 
Posts: 5
Joined: Mon Nov 03, 2014 1:43 pm

Re: intercepting arbitrary javascript function calls

Postby ViswanathCt » Tue Nov 04, 2014 11:47 pm

As stated above you could use js to hijack specific calls. For example, if you want to intercept foo(), so that it should call the function interceptor(), every time it's called; you can do the following:

Code: Select all

var _foo = foo
, foo = function() {

  interceptor();
  _foo();
}



But if you want to intercept arbitrary functions, without js; I guess it falls beyond the scope of CEF. You might need to work with Chromium or V8.
ViswanathCt
Newbie
 
Posts: 7
Joined: Tue Sep 09, 2014 10:28 pm

Re: intercepting arbitrary javascript function calls

Postby mrp » Wed Nov 05, 2014 1:40 am

ViswanathCt wrote:But if you want to intercept arbitrary functions, without js; I guess it falls beyond the scope of CEF. You might need to work with Chromium or V8.


I am confused by the above statement. I thought V8 is also part of CEF. No?

I am familiar with how to modify function behavior in js but I want to intercept the call in the CEF render process, if it is possible.

Thanks.
mrp
Newbie
 
Posts: 5
Joined: Mon Nov 03, 2014 1:43 pm

Re: intercepting arbitrary javascript function calls

Postby magreenblatt » Fri Nov 07, 2014 10:54 am

You can't intercept arbitrary JS object/function calls with C++, but you can intercept specific ones. For example, replace the default JS object with your custom interceptor object that calls a natively bound C++ function for each JS function.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: intercepting arbitrary javascript function calls

Postby mrp » Fri Nov 07, 2014 2:00 pm

magreenblatt wrote:You can't intercept arbitrary JS object/function calls with C++, but you can intercept specific ones. For example, replace the default JS object with your custom interceptor object that calls a natively bound C++ function for each JS function.


Thank you. I figured as much. I also realized that if I provide an implementation in javascript the V8 handler wont be invoked. It took me a while to figure it out the hard way. Is this documented somewhere?

Again thanks for all the replies.
mrp
Newbie
 
Posts: 5
Joined: Mon Nov 03, 2014 1:43 pm

Re: intercepting arbitrary javascript function calls

Postby magreenblatt » Fri Nov 07, 2014 2:05 pm

mrp wrote:Is this documented somewhere?

https://code.google.com/p/chromiumembed ... ntegration
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 34 guests