I want to create a Chrome extension that runs through a forum and copies all the links to each post on a particular page to a Google Spreadsheet. I can't find much on using Google Apps Script in a Chrome Extension - does anyone have any resources or can you point me in the right direction? Thanks in advance!
Asked
Active
Viewed 266 times
-1
-
1possible duplicate of [Can I execute Google Apps Script code from a Chrome extension?](http://stackoverflow.com/questions/18404922/can-i-execute-google-apps-script-code-from-a-chrome-extension) – HDCerberus May 13 '15 at 18:31
2 Answers
2
You can absolutely launch an Apps Script published as a web app from a chrome extension. Here is a simple example. This extension will ask you to launch a script every time you open www.google.com. Annoying, but I tried to make it as simple as possible.
Background.js
// Handle requests for script launch
chrome.runtime.onMessage.addListener(function(request) {
if (request.type === 'launch_script') {
chrome.tabs.create({
url: 'https://script.google.com/a/macros/YOUR SCRIPT URL/exec',
active: false
}, function(tab) {
// After the tab has been created, open a window to inject the tab
chrome.windows.create({
tabId: tab.id,
type: 'popup',
focused: true
// incognito, top, left, ...
});
});
}
});
manifest.json
{
"name": "Script Launch Test",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_scripts": [{
"matches": ["https://www.google.com/*"],
"js": ["open-dialog.js"]
}]
}
open-dialog.js
if (confirm('Launch Script?'))
chrome.runtime.sendMessage({type:'launch_script'});

Spencer Easton
- 5,642
- 1
- 16
- 25
-
this is not what is being asked. op wants to WRITE to a spreadsheet using apps script – Zig Mandel May 13 '15 at 21:37
-
1If you can launch a webapp script, you can use the DocumentApp/SpreadsheetApp service. – Spencer Easton May 13 '15 at 22:57
-
thats not a good way to do it. one would use ajax with a content service, not opening a new tab with a webapp. – Zig Mandel May 13 '15 at 23:32
1
The basic answer is yes, this is possible. This answer to a similar question includes a minimal working example.
However, given the restrictions GAS works under, I would instead consider skipping the Apps script part entirely, and instead using the Sheets APIs to access the content directly.

Community
- 1
- 1

HDCerberus
- 2,113
- 4
- 20
- 36