I've been trying to make a simple Chrome Extension using React. The manifest looks something like this:
{
"name": "New Tab",
"version": "1.0",
"manifest_version": 2,
"description": "A minimalist replacement for Chrome's New Tab page.",
"chrome_url_overrides": {
"newtab": "index.html"
},
"permissions": ["tabs", "topSites"]
}
I'm not sure how to actually use the Chrome topSites API in React. I've been looking at the documentation https://developer.chrome.com/extensions/topSites but it doesn't provide much insight. I'm trying to do something like this to get an array of data.
chrome.topSites.get(console.log)
However,
'chrome' is not defined no-undef
Normally, when you create a Chrome extension, you need to create a manifest. json file, but we're in luck! Create React App creates a manifest. json file by default — you can find it in your public folder.
React Native for Web is designed and tested for recent mobile and desktop browsers, for touch and mouse and keyboard interactions. The browsers with known support include: Chrome 60+
You can define chrome by adding /*global chrome*/
in the top of the file.
For Example
/*global chrome*/
import React, { Component } from 'react';
import './App.css';
class App extends Component {
componentWillMount() {
chrome.storage.local.set({ 'data' : 'Your data'}, function(result) {
console.log(" Data saved ")
});
}
render() {
return (
<div className="App">
</div>
);
}
}
export default App;
You need to disable the ESLint rule no-undef
and then enable it again:
/* eslint-disable no-undef */
function callback(val) {
console.log(val)
}
chrome.topSites.get(callback);
/* eslint-enable no-undef */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With