Google Chrome扩展程序-防止在jquery ajax请求上使用cookie或使用chome.extension [英] Google Chrome Extension - prevent cookie on jquery ajax request or Use a chome.extension
问题描述
我现在有一个很棒的chrome扩展程序.
I have a great working chrome extension now.
如果用户没有付费将图像显示在主列表中,则它基本上循环遍历Web拍卖网站的HTML列表.显示默认图像.
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.
- 我的插件使用jQuery Ajax请求加载拍卖页面并找到要显示为任何丢失图像的缩略图的主图像.很棒.
- 该插件找到正确的图片网址,并将HTML Dom更新为新图片并设置新宽度.
问题是,拍卖网站会跟踪所有页面的浏览量,并将其保存到网站的用户最近可以浏览的部分"
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"
问题 -我的插件使用ajax,并且cookie通过jQuery ajax请求发送.我敢肯定,我无法在此请求中修改Cookie,因此拍卖网站会跟踪该请求,并且对于任何缺少图片的列表,即使我实际上没有导航到该列表,该列表现在仍显示在最近查看"中.
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.
- 我可以删除针对ajax请求的cookie(我不认为可以)
- Chrome是否可以删除cookie(仅适用于ajax请求)
- 我可以让chrome发出请求(例如卷曲,没有cookie吗?)
只是出于好奇. 这是该拍卖网站上缺少图片的页面
Just for the curious. Here is a page with missing images on this auction site
推荐答案
您可以使用 webRequest
API,用于拦截和修改请求(包括空白标头).但是,它不能用于修改在Chrome扩展程序的上下文中创建的请求.如果要使用此API来进行cookie屏蔽,则必须在非扩展上下文中加载页面.通过创建新标签页,或使用屏幕外标签(使用实验性offscreenTabs API .
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.
另一种选择是使用 chrome.cookie
API,并绑定一个onChanged
事件.然后,您可以拦截Cookie的修改,并使用 chrome.cookies.set
.
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:
- 用户可以禁止进入隐身模式
- 用户本可以以隐身模式导航到该页面,从而导致cookie字段被填充.
- 具有破坏性:创建一个新窗口.
这篇关于Google Chrome扩展程序-防止在jquery ajax请求上使用cookie或使用chome.extension的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!