Welcome Guest, Not a member yet? Register   Sign In
need to communicate with Extension
#11

Here is how they do it using jQuery and a background js file.

CREATING A CHROME EXTENSION THAT USES JQUERY TO MANIPULATE THE DOM OF A PAGE
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#12

(04-15-2019, 05:21 AM)richb201 Wrote: I changed the .js function. Now it is this:
Code:
$(register_extension(
   var editorExtensionId = "mebiphcpglaighebopfapfoiimgnnbpf";

   // Make a simple request:
   chrome.runtime.sendMessage(editorExtensionId, "register_extension",
       function(response) {
           if (!response.success)
                  handleError(url);

})

I tried calling this by using register_extension() in my  directly in my controller. I am getting this error

Fatal error: Call to undefined function register_extension() in /var/www/html/sub_crud/application/controllers/Configure.php on line 60

I guess I can't call a js function even in a .js file? How should I handle this?
Similar to cross-extension messaging, your app or extension can receive and respond to messages from regular web pages. 
Reply
#13

(This post was last modified: 05-28-2019, 11:32 AM by MAILITY.)

(04-14-2019, 10:06 AM)richb201 Wrote:
(04-14-2019, 08:28 AM)InsiteFX Wrote: Is this what your trying to do?

Run chrome extension and submit data to PHP script on page load (automate the process)

Yes exactly. I created the .js file and am calling it with load_js(). In the file called by load js it doesn't seem to fire. I have tried both (document).load() and also (window).load() -->Audacity Find My iPhone Origin. Neither seems to fire. And how do I get a return code from the load_js? I need the web page to know if my extension is loaded and running. I could probably load a global return code just on this users pc?Could it be that my xdebug just can't debug js embedded in an html? I have the Chrome debugger on the extension, but it is not firing. I will read your quote now.

I have a Chrome Extension that is installed in the same browser that is hosting my CI based app. I need to communicate from the web app to the Extension. I was told that I could do this by running this in the web app:
Reply
#14

(This post was last modified: 05-26-2019, 04:48 AM by richb201.)

Well, with your guys help I managed to get the javascript running in a view. I am just having a small issue. I need to pass some data from my controller to the view.  I am using this:
       $data = array(
           'command' => "snapshot_mode",
           'userid' => "email",
           'campaign' => "campaign",
           'param_1' => "My Title"
           );

       $this->load->view("javascript_funcs_extensionloaded", $data, TRUE);

And here is the view:

  $(document).ready( function(data) {
       var editorExtensionId = "lamacgnkfoiknjpleghfknfigbmhdaei";
       // unload when done
       $(window).on('beforeunload',(function(){
           chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode_unload")
       }))
     
        jsonData=JSON.stringify(data)
     
       chrome.runtime.sendMessage(editorExtensionId, jsonData);
       })

This is not sending the jsonData to the extension. However, if I hard code in 

chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode2");

that seems to work fine. So I think that the $data in php is not being passed to the data variable in the view. How to fix this?
proof that an old dog can learn new tricks
Reply
#15

I was informed by phpStorm support that I cannot debug a php file as javascript. So I had application/views/javascript_funcs_extensionloaded.php that had my javsascript file. I was able to run the javascript but unable to debug it. So I changed it to application/views/javascript_funcs_extensionloaded.js. Now I can't run javascript at all.
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB