Skip to content

Instantly share code, notes, and snippets.

@ohaddahan
Created August 26, 2019 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohaddahan/b46165763ab5fd10173c1f39432736b7 to your computer and use it in GitHub Desktop.
Save ohaddahan/b46165763ab5fd10173c1f39432736b7 to your computer and use it in GitHub Desktop.
/*global chrome*/
import React from 'react';
//import logo from './logo.svg';
import './App.css';
import Dashboard from "./components/Dashboard";
export default class App extends React.Component {
componentWillMount() {
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
}
render() {
return (
<div className="App">
<Dashboard/>
</div>
);
}
}
// This code gets called when I click a button, it's inside Dashboard -> Button
foo() {
chrome.runtime.sendMessage(getExtension(), {greeting: "hello"}, function(response) {
console.log(response);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment