使用隐私浏览时如何从他们的 public 端点提取 Reddit 数据?
How to pull Reddit data from their public endpoint when using private browsing?
在使用 Firefox 的隐私浏览模式时,我无法使用 AJAX 从 public Reddit API 中提取数据。该代码在不处于隐私浏览模式时工作正常。
public API,我指的是像 https://reddit.com/r/funny/.json 这样的端点请注意,如果您尝试这样做,link 将在常规或隐私浏览模式下工作直接去那里。但是,使用 AJAX 中的相同 link not 在隐私浏览模式下工作,如以下代码所示:
var url = "https://www.reddit.com/r/funny/.json?limit=4";
$.ajax({
type: 'GET',
url: url,
dataType: 'jsonp',
success: function(data) { $('#foo').append('<p>Success!</p>'); },
error: function() { $('#foo').append('<p>Failure!</p>'); },
jsonp: 'jsonp'
});
JSFiddle link (在常规浏览和私人浏览中尝试 windows)
我认为 JSONP 在这种情况下可能会有所帮助,但事实并非如此,或者我只是做错了。 JSONP 文档似乎非常稀少,尤其是当它与 Reddit API.
相关时
Firefox 在发送请求时在控制台中显示的错误是:
The resource at “https://www.reddit.com/r/funny/.json?limit=4&jsonp=jQuery400175737938774993335244664702950021422623963_1631658838396&_=1631658838397” was blocked because content blocking is enabled.
在私人模式下或启用增强型跟踪保护,Firefox 72 及更高版本 will block third-party requests to some domains, according to a list by disconnect.me, which can be found on GitHub。
reddit.com 是这些域之一,被归类为“FingerprintingGeneral”和“Social”。根据 Mozilla blog 中的脚注:
A tracker on Disconnect’s blocklist is any domain in the Advertising, Analytics, Social, Content, or Disconnect category. A fingerprinter is any domain in the Fingerprinting category. Firefox blocks domains in the intersection of these two classifications, i.e., a domain that is both in one of the tracking categories and in the fingerprinting category.
(强调,这些是适用于此处的分类)
要显示该内容以使其在 Firefox 和其他具有类似跟踪保护的浏览器中也能正常工作,最安全的做法可能是从您自己的 API 后端获取数据,而不是直接向 Reddit 发送请求来自前端。
或者,如果这不是一个选项,您可以添加良好的错误处理并要求您的用户为您的网站禁用增强型跟踪保护以查看他们错过的内容。
在使用 Firefox 的隐私浏览模式时,我无法使用 AJAX 从 public Reddit API 中提取数据。该代码在不处于隐私浏览模式时工作正常。
public API,我指的是像 https://reddit.com/r/funny/.json 这样的端点请注意,如果您尝试这样做,link 将在常规或隐私浏览模式下工作直接去那里。但是,使用 AJAX 中的相同 link not 在隐私浏览模式下工作,如以下代码所示:
var url = "https://www.reddit.com/r/funny/.json?limit=4";
$.ajax({
type: 'GET',
url: url,
dataType: 'jsonp',
success: function(data) { $('#foo').append('<p>Success!</p>'); },
error: function() { $('#foo').append('<p>Failure!</p>'); },
jsonp: 'jsonp'
});
JSFiddle link (在常规浏览和私人浏览中尝试 windows)
我认为 JSONP 在这种情况下可能会有所帮助,但事实并非如此,或者我只是做错了。 JSONP 文档似乎非常稀少,尤其是当它与 Reddit API.
相关时Firefox 在发送请求时在控制台中显示的错误是:
The resource at “https://www.reddit.com/r/funny/.json?limit=4&jsonp=jQuery400175737938774993335244664702950021422623963_1631658838396&_=1631658838397” was blocked because content blocking is enabled.
在私人模式下或启用增强型跟踪保护,Firefox 72 及更高版本 will block third-party requests to some domains, according to a list by disconnect.me, which can be found on GitHub。
reddit.com 是这些域之一,被归类为“FingerprintingGeneral”和“Social”。根据 Mozilla blog 中的脚注:
A tracker on Disconnect’s blocklist is any domain in the Advertising, Analytics, Social, Content, or Disconnect category. A fingerprinter is any domain in the Fingerprinting category. Firefox blocks domains in the intersection of these two classifications, i.e., a domain that is both in one of the tracking categories and in the fingerprinting category.
(强调,这些是适用于此处的分类)
要显示该内容以使其在 Firefox 和其他具有类似跟踪保护的浏览器中也能正常工作,最安全的做法可能是从您自己的 API 后端获取数据,而不是直接向 Reddit 发送请求来自前端。
或者,如果这不是一个选项,您可以添加良好的错误处理并要求您的用户为您的网站禁用增强型跟踪保护以查看他们错过的内容。