Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 8 of 8

This is a discussion on Access to DOM(Document Object Model) within the Plugins Development section, part of the Chrome Plugins category: Hi, I'm a developper. Our company develops a french spell-checker and grammar-checker. Our software interacts with a word processors and ...


  1. #1
    chello is offline Junior Member
    Join Date
    Nov 2009
    Posts
    4

    Default Access to DOM(Document Object Model)

    Hi,
    I'm a developper. Our company develops a french spell-checker and grammar-checker. Our software interacts with a word processors and browsers. I would like to establish a communication between our software and the Google Chrome browser within a C++ plugin. To reach my goal, I need to get access to the DOM (document object model) of the current window. By exemple, the interaction between our software and Firefox is performed with the XPCOM technology.

    I would like some hints to start my projet. The communication can be establishes with the NPAPI technology. But, how can I get acces to DOM?

    Best Regards,
    Pierre

  2. #2
    Skymt is offline Junior Member
    Join Date
    Nov 2009
    Posts
    20

    Default

    Hey, chello.
    The only part of a Chrome extension that has access to the DOM, is the content scripts.
    See http://code.google.com/chrome/extens...t_scripts.html

    They also have some documentation about NPAPI plugins..
    http://code.google.com/chrome/extensions/npapi.html

  3. #3
    chello is offline Junior Member
    Join Date
    Nov 2009
    Posts
    4

    Default

    Thank you for your answer,

    I have created a plugin with NPAPI technology. This plugin is a bridge between our software and Google Chrome. But now, I have to access to DOM of the current window of Google Chrome. The only way to access DOM is with JavaScrpit. Then I have tried (without success) to use V8 JavaScript engine the execute JavaScript function. I use as template the Hello Word example (http://code.google.com/intl/fr/apis/v8/get_started.html).

    What I have to do to execute JavaScript function within my NPAPI plugin? The javascript function have to execute action on the DOM of the current window of Google Chrome.

    Thank.

  4. #4
    chello is offline Junior Member
    Join Date
    Nov 2009
    Posts
    4

    Default call javascript function with V8 within NPAPI plugin

    Thank you for your answer,

    I have created a plugin with NPAPI technology. This plugin is a bridge between our software and Google Chrome. But now, I have to access to DOM of the current window of Google Chrome. The only way to access DOM is with JavaScrpit. Then I have tried (without success) to use V8 javascript engine the execute javascript function. I use as template the Hello Word example (http://code.google.com/intl/fr/apis/v8/get_started.html).

    What I have to do to execute javascript function within my NPAPI plugin? The javascript function have to execute action on the DOM of the current window of Google Chrome.

    Thank.

  5. #5
    Skymt is offline Junior Member
    Join Date
    Nov 2009
    Posts
    20

    Default

    Hm.. I have no real expertise in this technology, but even if the V8 javascript does not have access to the DOM, it should have access to the chrome namespace.

    You can try sending a message to a content script.

    Here is an example of message passing. This is the code I use, to read a value from localStorage in my background DOM to figure out if the user has enabled the option "site integration" in the options page:

    background.js - the listener.
    Code:
    chrome.extension.onRequest.addListener(function (request, sender, sendResponse) {
            if (request.target) {
                switch (request.target) {
                    case "siteIntegration": sendResponse({ GoAhead: eval(localStorage[request.target]) }); return;
    [...]
    content script.js - the sender.
    Code:
    chrome.extension.sendRequest({target: "siteIntegration"}, function(response) { if(response.GoAhead) manipulatePage(); });
    If you set up a listener in your content script, your V8 code could send the request. The content script can then collect the needed information from the site DOM and return it, like I do above.

    Messaging:
    http://code.google.com/chrome/extensions/messaging.html

  6. #6
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    lol.. NPAPI has access to everything. Your only hurdle is getting into the page's sandbox. It seems the quickest and most efficient way is through Content Scripts, however.
    Skymt's communication example isn't really gonna help at all with Content Script to NPAPI communication though..
    There's an example of how to interact with your NPAPI plugin here, which you will need to do anyway just to activate the plugin (by injecting it into the page, and executing its main function). At least I'm assuming you'll be wanting to check spelling in the DOM. :P
    That example, however, is for a Background Page, or other HTML page in your extension. Here's an example for how to inject it directly into the page from a Content Script:

    Code:
    var embed = document.createElement("embed");
    document.setAttribute("type","application/x-my-extension");
    document.setAttribute("id","pluginId");
    document.body.appendChild(embed);
    var plugin = document.getElementById("pluginId");
    var result = plugin.myPluginMethod();  // call a method in your plugin
    console.log("my plugin returned: " + result);
    Once you do that, you can loop through all the text elements (you can return them all with document.getElementsByTagName("input") then parse so for type="text" and document.getElementsByTagName("textarea")) and addEventListeners to the "keyup" event or whatever you want to call spell check.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  7. #7
    neb
    neb is offline Junior Member
    Join Date
    Feb 2010
    Posts
    1

    Default

    The API to use is called NPRuntime, it's part of NPAPI. Reference is at https://developer.mozilla.org/en/Gec...ipting_plugins

    Getting a hold of DOM is described under 'accessing browser objects from a plugin', and boils down to calling NPN_GetValue with NPNVWindowNPObject as the variable. You get back the window object and then you can get anything you want from there - e.g. call NPN_GetProperty to get the document, then call NPN_Invoke on the document to invoke getElementById.

  8. #8
    int0 is offline Junior Member
    Join Date
    May 2010
    Posts
    1

    Default

    Hi,
    I'm a beginner in NPAPI and i would like to implement function in my plugin that read data from DOM. But i don't understand how to do it. I read link from previous post but there is not much information for me. Could you please write a simple example how to get DOM.
    Best Regards,
    Igor

Similar Threads

  1. Tree-view Object Browser extension
    By Waha in forum Plugins Development
    Replies: 18
    Last Post: 05-28-2011, 12:32 AM
  2. Cannot access site...
    By mg2 in forum Chrome Troubleshooting
    Replies: 17
    Last Post: 11-30-2009, 08:10 PM
  3. [New Ext]Access Extension Panel
    By karajanlee in forum Chrome Plugins
    Replies: 10
    Last Post: 09-24-2009, 06:46 PM
  4. An actually complete and well document API reference. O.o
    By Waha in forum Plugins Development
    Replies: 1
    Last Post: 09-04-2009, 05:28 AM
  5. What program can I use to extract object?
    By ducktape in forum General Chat
    Replies: 5
    Last Post: 08-15-2009, 09:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •