Can i intercept JS functions calls via CefRegisterExtension?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Can i intercept JS functions calls via CefRegisterExtension?

Postby eren » Fri Sep 19, 2014 7:03 am

Hi! I'm using CEF3 and I need to intercept confirm() JS function call.

I'm trying to do this via CefRegisterExtension like this:
Code: Select all
void ClientApp::OnWebKitInitialized()
{
   // Register the client_app extension.
   // ...
   // ...
   // ...

   // Register the confirm() JS function intercept extension.
   std::string intercept_js_code =
      "(function() { "
      "   window.confirm = function () { "
      "      alert('intercepted'); "
      "      return true; "
      "   } "
      "})(); "
      ;
   CefRegisterExtension("v8/ijs", intercept_js_code,
      new ClientAppExtensionHandler(this));

   RenderDelegateSet::iterator it = render_delegates_.begin();
   for (; it != render_delegates_.end(); ++it)
      (*it)->OnWebKitInitialized(this);
}

With the intercept_js_code inserted to the frame every call of JS confirm() should result in showing an alert box with text "intercepted". But instead of this none of web-pages is ever loaded while the "v8/ijs" extension is registered.

Chromium just showing the blank page and loading forever...

So, what is wrong?
And how do i achieve the interception of confirm() JS function call?
CEF v3.1650.1567_windows32
eren
Techie
 
Posts: 25
Joined: Mon Feb 03, 2014 8:11 am

Re: Can i intercept JS functions calls via CefRegisterExtens

Postby Czarek » Fri Sep 19, 2014 7:18 am

See CefJSDialogHandler::OnJSDialog.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Can i intercept JS functions calls via CefRegisterExtens

Postby eren » Fri Sep 19, 2014 7:27 am

Czarek wrote:See CefJSDialogHandler::OnJSDialog.

Thanks! That is exactly what i was looking for.
But i'm still curious what is wrong with my attempt to do this via CefRegisterExtension.
CEF v3.1650.1567_windows32
eren
Techie
 
Posts: 25
Joined: Mon Feb 03, 2014 8:11 am

Re: Can i intercept JS functions calls via CefRegisterExtens

Postby eren » Fri Sep 19, 2014 8:15 am

And i don't quite get where should i override this method CefJSDialogHandler::OnJSDialog.
CEF v3.1650.1567_windows32
eren
Techie
 
Posts: 25
Joined: Mon Feb 03, 2014 8:11 am

Re: Can i intercept JS functions calls via CefRegisterExtens

Postby Czarek » Fri Sep 19, 2014 8:31 am

Return CefJSDialogHandler instance in CefClient::GetJSDialogHandler. See SimpleHandler for an example: https://code.google.com/p/chromiumembed ... i/Tutorial
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Can i intercept JS functions calls via CefRegisterExtens

Postby eren » Fri Sep 19, 2014 9:45 am

Czarek wrote:Return CefJSDialogHandler instance in CefClient::GetJSDialogHandler.

Yep, it worked. Thank you once again.
CEF v3.1650.1567_windows32
eren
Techie
 
Posts: 25
Joined: Mon Feb 03, 2014 8:11 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 88 guests

cron