Chrome Extension x Delphi

Asked

Viewed 982 times

2

Does anyone know how to communicate an extension created for CHROME with DELPHI ?

Something like sending DELPHI commands to that extension OR vice versa ?

Follow the extension code that captures the CURRENT TAB code.

function DOMtoString(document_root) {
    var html = '',
        node = document_root.firstChild;
    while (node) {
        switch (node.nodeType) {
        case Node.ELEMENT_NODE:
            html += node.outerHTML;
            break;
        case Node.TEXT_NODE:
            html += node.nodeValue;
            break;
        case Node.CDATA_SECTION_NODE:
            html += '<![CDATA[' + node.nodeValue + ']]>';
            break;
        case Node.COMMENT_NODE:
            html += '<!--' + node.nodeValue + '-->';
            break;
        case Node.DOCUMENT_TYPE_NODE:
            // (X)HTML documents are identified by public identifiers
            html += "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>\n';
            break;
        }
        node = node.nextSibling;
    }
    return html;
}

chrome.extension.sendMessage({
    action: "getSource",
    source: DOMtoString(document)
});
  • Explain it better. Is it an external server written in Delphi? It’s a program running on the client machine at the same time as Chrome?

  • I created an extension for CHROME that captures the browser source code in REAL TIME, through a JAVASCRIPT function. Now I need to make DELPHI take this function and play in a MEMO or something related, I don’t know if you can do this, more if you give, the interest of the project would be this.

  • I put the code above Amigo..

1 answer

3


It is unclear whether you want to communicate with a program written in Delphi on the local machine or remotely under the internet. In any case the solution is to open an HTTP server by Delphi and handle requests generated by the extension. On the extension you can send a POST request to the IP of the machine running the Delphi program (127.0.0.1 if it is the computer itself). The server can be a CGI application, for example, listening on some specific port that the extension knows. That’s the basic idea.

It seems to me that there are no other means (even for security reasons) of the extension accessing something from the computer, whatever. The only form of communication would be with AJAX itself.

  • It will be a program running on the client’s own machine yes, everything localhost. I will have a FORM DELPHI with a MEMO. I need CHROME to connect to this form in real time and send the html source code in the current tab (in this case my javascript function), it can even be via Serversocket or something related.

  • @user7605 then what I said answers the problem. It’s just you leave for the implementation now. There should be no difficulty from here. But if there is create a new question to address the specific difficulty you find while implementing.

  • OK Buddy, thanks for the help, I’m already on the internet studying this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.