Hello guys,
I want to be able to access informations stored in chrome.storage.sync from an inline script within a web page, injected by my extension.
When trying to use chrome.storage.sync, sync can't be called from "undefined". In the same way, I couldn't call chrome.runtime.sendMessage. This answer taught me I can't access Chrome APIs from an injected script.
I found out that I could eventually call sendMessage using this technique : https://developer.chrome.com/extensions/messaging#external-webpage and then I could return the wanted data in the callback.
But I wanted to know, is there a better way to do this ? Accessing chrome.storage data from the injected script ? The fact that I need to use my extension's as an argument is really not great...
Thanks !
Since your injected script is essentially the same as the page's own code from a security perspective, there's no way to make this task easy.
externally_connectable that you found is one of the ways to do it.
The other way is to talk with the content script itself. You can do so with custom events or window.postMessage.
Related
I used this code to insert documents directly into a Google spreadsheet without having to upload files and then create hyperlinks. However, as google moved to the new spreadsheet...
Warning: The UI service was deprecated on December 11, 2014. To create user interfaces, use the HTML service instead.
So know I need help fixing lines like; var app = UiApp.getActiveApplication();
If someone could clarify the different types of programming direction you could take this project from, that would also be very helpful, I am not really sure if I need to work with Javascript or HTML now.
The answer to your question will depend in large part on how you are using UIApp. In most cases it's not as simple as changing a few lines of code but more of a script redesign.
If you are using it to create a custom user interface, your path forward would be to rebuild your interface as HTML/Javascript and serve it to the user with HTMLService. The service is overall much more powerful/flexible and provides a better end-user experience but it means rewriting how your script works. If you want to take a look at a helpful example on how the HTML Service works take a look at the HTML Service Guide or this quick-start example of an add on.
You can still link this html interface with your script using the google.script.run service but you will need to redesign your code/application to work with the new input methods. The good news is although UI service will sunset on June 30, 2015, "Service will no longer appear in autocomplete, although existing scripts should still function."
It's worth considering alternate ways to accomplish the same goal. The best way to do that is to start by asking "What is the intended use of this script? What problem does it solve?" There may be a better way to accomplish that task which may not even involve updating the script.
This is not related to the new spreadsheet version, the message you get is because UiApp has recently been deprecated.
A Google search would have shown you a few tracks to find your way.
One of the best I found is this one from Sandy Good : Google apps script UI services to HTML services
It shows a typical example of conversion to HTMLService.
I'm building a community driven website off of Google sites (I know this is a bad choice, I don't have a choice in the matter) and the majority of the functionality is build into Google Apps Scripts (to read/write to an external database and handle how data is displayed). Amid various issues, I've found one that consistently confuses me.
I typically structure my GAS projects into Javascript, HTML, and CSS (Code.gs, HTML.html, and CSS.html). I leverage jQuery for quite a few things (e.g., click handlers, form submission, etc). However, it seems that my jQuery and my Javascript can't exist in the same "world", here meaning in the same .gs file, or the same script tags if it's going in the HTML file. In fact, I can't call any jQuery functions from my .gs file! Can someone explain why this is, please? It seems like the problem is that the jQuery library isn't included, but I can't find a way to include anything in Javascript (think #include from C). And since this is web programming, which is pretty different from "normal" programming, I think that part of my problem understanding this comes from here. And working inside a framework (GAS) doesn't help.
Much obliged, thank you.
HTML Service supports JQuery because the code is executed in your Browser, so the library is loaded in your browser too (after CAJA sanitization) but the code in the .gs file is executed on Google's server and you can't obviously load anything on Google's server !
In one word : there is no way to use JQuery or any other external library in Google Apps Script files other than .html files used in HTML Service.
In the project configuration you're describing, which matches the examples from the HtmlService Best Practices, all your GS code runs server-side, while the regular javascript and jQuery run client-side, in the user's browser. If you've got GS in your HTML files, then I expect you're using templated HTML, which in turn means that the GS is evaluated server-side to produce the final HTML that gets served to the client. (Take a look at the HTML source once the page is served up... no GAS in there.)
So it's those different operating contexts that keep your GAS & jQuery elements from interacting directly. From the client, you can use google.script.run for instance, to call server-side functions and pass parameters to them, and you can also set up call-backs to receive asynchronous "returns" from your GS code.
Given the reliance on DOM elements, I am not sure what use there would be in having jQuery in server-side Apps Script, but this blog entry from #EricKoleda provides an example of porting an open source javascript library to Google Apps Script. (Maybe you'll find his copy of the Underscore Library to be all you need!)
I recently discovered a parameter to pass to a google hangout uri to make it "on air": reference
I'm also wondering if I can pass any other parameters. I know that we have app_id, but I'm more interested to know if there are other parameters, such as being able to set the title or the hangout in advance, e.g.
https://plus.google.com/hangouts/_?hso=0&title=EdX%20SaaS%20Pairing
Because then I could direct people to https://plus.google.com/u/0/s/%23hangoutsonair%20EdX/hangouts and they could see all the on air hangouts associated with our MOOC. I did experimentally try passing title=, topic= and name= all to no immediate effect ...
I'd also love to know if there's a way to automatically start the live broadcast, or even better have the hangout be automatically associated with and published to our G+ pair programming community:
https://plus.google.com/communities/100279740984094902927
Many thanks in advance
Got this response from Tim Blasi at Google:
I'm a developer working on video calling. Unfortunately, you can not currently configure the video call in the way you are describing. However, we've received a lot of feedback that this is a pain point and we're currently working to address it. We'll keep your request in mind as we move forward.
https://plus.google.com/u/0/103524399391704001670/posts/JGtpxgvdD5H
resurrecting an old thread, but for a good reason.
i recently found that its possible to bypass the landing page and pre-select your user account
https://meet.google.com/lookup/my-room-name?authuser=my-email#account.com
just replace my-room-name and my-email#account.com
i have been going around in circles here and have totally confused myself. I need some help.
I am (trying to) writing an application for a client that in concept is simple. he want a google write document with a button. the google drive account has several folders, each shared with several people. when he drops a new file in one of the folders, he wants to be able to open this write file, this file is the template for his email. he clicks the button, the system calls the changes service in the Google Drive SDK https://developers.google.com/drive/manage-changes, gets the list of files that have been added since the last time it was checked, then pull the list of people that the file has been shared with, and use the write file as a template to send that list of people an email saying their file is ready.
SO, easy enough, right?
I started by looking at the built in functions in the Google App Script API. I found this method, https://developers.google.com/apps-script/class_docslist#find in the DocsList class. problem is the description for the query simply says "the query string". So at first i tried the Drive SDK query parameters, which are
var files = DocsList.find("modifiedDate > 2012-12-20T12:00:00-08:00.");
it didn't work. that leads me to believe it is a simple full text search on the content. Thats not good enough.
That lead me into trying to call a Drive SDK method from within an App Script application. Great, we need an OLap 2 authentication. easy enough. found the objects in the script reference and hit my wall.
Client ID and Client Secret.
you see, when i create what this really is, a service account, the olap control in apps script doesn't know how to handle the encrypted json and pass it back and forth. Then when i tried to create and use an installed applications key, i get authentication errors because the controls again, don't know what to do with the workflow. and finally, when i try to create a web app key, i can't because i don't have the site host name or redirect URI. And i can't use the application key ability because since im working with files OLap 2 is required.
i used the anonymous olap for a while, but hit the limit of anonymous calls per day in the effort of trying to figure out the code a bit, thats not going to work because the guy is going to be pushing this button constantly thru the day.
i have been pounding my head on the desk over this for 5 hours now. i need some help here, can anyone give me a direction to go?
PS, yes, i know i can use the database controls and load the entire list of files into memory and compare it to the list of files in the database. problem being, we are talking tens of thousands of files. bad idea.
I wouldn't use DocsList anymore - DriveApp is supposed to be a more reliable replacement. Some of the commands have changed, so instead of find, use searchFiles. This should work more effectively (they even use a query like yours as an example).
I'd like to try my hand at some Chrome Extension Development. The most I have done with extensions is writing some small Greasemonkey scripts in the past.
I would like to use localStorage to store some data and then reveal the data on a extension button click later on. (Its seems like this would be done with a popup page)
How do I run a script everytime a page from lets say http://www.facebook.com/* is loaded?
How do I get access to the page? I think based off my localStorage requirement I would have to go down the background_page route (correct?) Can the background page and popup page communicate across the localStorage?
UPDATE:
I'm actually looking to learn the "Chrome way". I'm not really looking to run an existing Greasemonkey script
Google actually has some pretty good documentation on creating extensions. I recommend thoroughly reading the following two articles if you haven't already done so:
http://code.google.com/chrome/extensions/getstarted.html
http://code.google.com/chrome/extensions/overview.html
If you want to give your extension access when the user browses to Facebook, you'll need to declare that in the extension's manifest.
Unless you're wanting to save data beyond the life of the browser process, you probably don't need to use local storage. In-memory data can just be stored as part of the background page.
Content scripts (which run when you load a page) and background pages (which exist for the duration of the browser process) can communicate via message passing, which is described here:
http://code.google.com/chrome/extensions/messaging.html
Overall, I'd suggest spending some time browsing the Developer's Guide and becoming familiar with the concepts and examples.
Chrome has a feature to automatically convert greasemonkey scripts to extensions!