I'm trying to build a chrome extension which should highlight certain things on the page if they appear in a user's google sheet.
When trying to initialize gapi object in the background script, I'm getting gapi.auth2.ExternallyVisibleError: Invalid cookiePolicy. When searching or this error i didn't really find a solution for my case (including this one).
I wanted to load the sheet into memory just once using gapi in the background script, and not do this in every tab (content script).
I also found several posts which mentioned that gapi and OAuth2 don't work well in chrome extensions, can anyone please explain? Is this a general no-no?
Related
I am a little confused whether this api suits my need. I want a common place to view my logs, instead of going around to the popup's console, the background page's console, etc...
Then I noticed that you can include several background scripts. In which case, which page does the api give us?
Chrome does not support multiple background pages in a chrome extension. It supports multiple background scripts. But it does not supports both background page and background scripts at the same time. See below the screenshots.
Error shown when we try add background page and script at the same
time.
Error shown when we try add multiple background pages.
Now coming back to your question which page getBackgroundPage() retrieve?
Since chrome supports only one background page it will return the only page that you include in you manifest.json.
Where in the Chromium source code can I modify the browser's User Agent String?
I am working with the Mac OS. Also, I do not want to append to the User Agent. Essentially, I want to change the UA enough so that a website still thinks it is Chrome (as is standard with Chromium UA), while it is not chrome.
I have had issues with appending a unique identifier in that it causes many websites to block my access.
This is definitely an old question, but it's a question I too have been searching for an answer for. Since StackOverflow results appear in Google search results, and that there isn't another question like this, it's a good idea to document it for others.
It's currently located in content\common\user_agent.cc
It used to be located in webkit\glue\user_agent.cc, but was moved around when Google forked it to make Blink.
Like dangered wolf mentioned, Google Chrome and Chromium build and retrieve user agent from this method BuildUserAgentFromOSAndProduct : Build Chromium's user-agent
And this is where Chrome will retrieve the final Chrome/version string from GetProductNameAndVersionForUserAgent : Retrieve Chrome/version string for user-agent
Recently I've been working on an idea that requires me to query Google Images and retrieve links for images matching that search term. My most promising candidate for a usable Google Images API was the Google Web Search API, but it looks like it's going to be going out of service as of tomorrow:
https://developers.google.com/web-search/docs/
The API that replaced it is the Google Custom Search API, but it's a little discouraging to use:
Google API Custom Search with Python - Programmatic Search Results
100 search results a day is a very strict limit; that's just four searches per hour. I also don't want to have to go through the hassle of creating some custom search bar that I'm never going to use except through Python
I decided to turn to parsing HTML directly from the results page. This presents a problem, though, because nowhere inside the page's HTML is there any direct link to the image, only referrer URLs. This is true of the javascript-enabled and javascript-disabled versions of Google Images (so even if Python spoofs javascript as enabled, nothing). I'm not sure where to go from here. Could anyone refer me to some obscure, updated library that I've somehow overlooked, or give me some pointers?
You could use Selenium Webdriver to actually execute the JavaScript and click on the images in the thumbnail view. Once an image has been opened, the link is in the DOM and you can scrape it from there. All Webdriver does is open an actual browser and simulate a user. You can even run it as a headless browser if you use xvfbwrapper. The downside is that even then, you will need all the dependencies of the browser you are using installed on your server.
However, scraping Google is against their terms of service and they will make an effort of blocking you as quickly as possible. So, unless you pass through the captchas (which are linked to sessions), you will possibly not be able to make a whole lot of searches before being blocked this way, either.
I want to be able to call functions that I am writing in a Chrome extension from the JS console in Chrome, so that I can test them easily and see how their output changes as the page changes.
But it seems as the functions I write aren't available to the chrome JS console. I don't really understand JS that well, or the chrome extension model, but I need to somehow inject the extension source into the body of the page that I am using the extension for?
If you are talking about functions that you defined in a background page, then you need to go to your extensions page, check the developer mode box, and click on _generated_background_page.html. That is where you will find your background page code.
If you mean functions in a content script, then when you are in the console, go down to where it says <page context> and change it to your extension. Then you will have access to the functions in the content script.
Is there a way to detect if a particular tab was POSTed to via a Google Chrome extension? I am working on an extension that includes an "undo closed tab" type of function and would like to handle tabs which were POSTed to differently than GET pages.
I believe a solution exists in chrome.webRequest.onBeforeRequest via the 'method' return parameter. I will report back with a working code example once I have time to try this out.