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

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:


Code:
chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url},
 function(response) {
   if (!response.success)
     handleError(url);
 });
This will generate a message that my Extension can see and react to.

The question is "how do I run the above code from my CI based php app"? Is that javascript that I can run when my app starts up? Since the server is generating HTML pages, how do I get this working? I do need to see the result of this call since I will "grey out" certain functions in my web app if the Extension is not found. 

Any clues? 
proof that an old dog can learn new tricks
Reply
#2

This should explain it to you.

Chrome - Message Passing
What did you Try? What did you Get? What did you Expect?

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

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

Yes, Insite, that is what I am following.

Sending messages from web pages
Similar to cross-extension messaging, your app or extension can receive and respond to messages from regular web pages.

a few lines down they have this example:

// The ID of the extension we want to talk to.
var editorExtensionId = "abcdefghijklmnoabcdefhijklmnoabc";

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

I thought maybe I could wrap this in javascript and drop it into the init function in my Controller:
PHP Code:
    private function _init()
 
     {

 
         $this->output->set_template('default2');

 
         $this->load->js('assets/themes/default/js/jquery-1.9.1.min.js');
 
         $this->load->js('assets/themes/default/hero_files/bootstrap-transition.js');
 
         $this->load->js('assets/themes/default/hero_files/bootstrap-collapse.js');
 
         $this->load->js('js/jquery.orgchart.js');     // for charts

 
         echo '<script type="text/javascript">'
 
         var editorExtensionId "abcdefghijklmnoabcdefhijklmnoabc";

 
       // Make a simple request:
 
       chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditorurl},
 
       function(response) {
 
            if (!response.success)
 
              handleError(url);
 
                    };
 
         '</script>'
 
     
But that 2nd line with the var is causing a parsing error. Am I going down the right path here? I assumed that I need to run javascript, but I guess I need to have it appear the rendered html, right? How do I do that?
proof that an old dog can learn new tricks
Reply
#4

To access the messaging you would need to do it using jQuery then do a post or get to
the controller to do what you need.
What did you Try? What did you Get? What did you Expect?

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

Is this what your trying to do?

Run chrome extension and submit data to PHP script on page load (automate the process)
What did you Try? What did you Get? What did you Expect?

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

(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(). 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.
proof that an old dog can learn new tricks
Reply
#7

You can use the Chrome developer tools to view what is happening F12.
What did you Try? What did you Get? What did you Expect?

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

(This post was last modified: 04-15-2019, 06:38 AM by richb201.)

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?
proof that an old dog can learn new tricks
Reply
#9

try calling it from your html view file.
What did you Try? What did you Get? What did you Expect?

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

I tried both calling it from the html section and also the php section of the view file. Or should I be loading is with load->view()?

Code:
<!DOCTYPE html>
<html>
<head>
   <title>Substantiator</title>
    <meta charset="utf-8" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   extensionloaded()    
   <?php


foreach($css_files as $file): ?>
    <link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($js_files as $file): ?>
    <script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
   <?php if( isset($html_title) && $html_title != '' ){
       echo '<title>' . $html_title . '</title>';
   } ?>
   </head>
<body>
<html>

<body>
<div id="chart_div"></div>
</body>
</html>
</body>
<!--Div that will hold the pie chart-->
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB