John Ballinger
John Ballinger

Reputation: 7550

Google Chrome Extension - prevent cookie on jquery ajax request or Use a chome.extension

I have a great working chrome extension now.

It basically loops over a list of HTML of a web auction site, if a user has not paid for to have the image shown in the main list. A default image is shown.

The issue is, that the auction site tracks all pages views and saves it to a "recently viewed" section of the site "users can see any auctions they have clicked on"

ISSUE - My plugin uses ajax and the cookies are sent via the jQuery ajax request. I am pretty sure I cannot modify the cookies in this request so the auction site tracks the request and for any listing that has a missing image this listing is now shown in my "recently viewed" even though I have not actually navigated to it.

  1. Can I remove cookies for ajax request (I dont think I can)
  2. Can chrome remove the cookie (only for the ajax requests)
  3. Could I get chrome to make the request (eg curl, with no cookie?)

Just for the curious. Here is a page with missing images on this auction site

http://www.trademe.co.nz/Browse/SearchResults.aspx?searchType=all&searchString=toaster&type=Search&generalSearch_keypresses=9&generalSearch_suggested=0

Thanks for any input, John.

Upvotes: 2

Views: 2618

Answers (2)

Rob W
Rob W

Reputation: 349192

You can use the webRequest API to intercept and modify requests (including blanking headers). It cannot be used to modify requests which are created within the context of a Chrome extension though. If you want to use this API for cookie-blanking purposes, you have to load the page in a non-extension context. Either by creating a new tab, or use an off-screen tab (using the experimental offscreenTabs API.

Another option is to use the chrome.cookie API, and bind a onChanged event. Then, you can intercept cookie modifications, and revert the changes using chrome.cookies.set.

The last option is to create a new window+tab in Incognito mode. This method is not reliable, and should not be used:

  • The user can disallow access to the Incognito mode
  • The user could have navigated to the page in incognito mode, causing cookie fields to be populated.
  • It's disruptive: A new window is created.

Upvotes: 4

Dan Smith
Dan Smith

Reputation: 5685

Presumably this AJAX interaction is being run from a content script? Could you run it from the background page instead and pass the data to the content script? I belive the background page operates in a different context and shouldn't send the normal cookies.

Upvotes: 0

Related Questions