Adding a content script
We're now at the stage where everything is in place to display stored contacts, so we can focus on actually getting some contacts. In order to interact with pages that the user navigates to in their browser, we need to add a content script.
A content script is just like a regular script, except that it interacts with the page being displayed in the browser instead of with the files that make up the extension. We'll see that we can post messages between these different areas (the page in the browser and the extension) in a similar way that we posted a message to our sandbox.
Engage Thrusters
First we'll need to add some new files to the chrome-extension
directory. We'll need a JavaScript file called content.js
and a style sheet called content.css
. We need to tell our extension to use these files, so we should also add a new section to the manifest file (manifest.json
) we created earlier in the project:
"content_scripts": [{ "matches": ["*://*/*"], "css": ["content...