New Safari extension: ChangeTheHeaders to customize HTTP request headers

New Safari extension: ChangeTheHeaders to customize HTTP request headers



New Safari extension: ChangeTheHeaders to customize HTTP request headers

March 27, 2025
By Jeff Johnson of Underpass App Company

I’m happy to announce that I’ve just released a new app! ChangeTheHeaders is a Safari extension for iOS, iPadOS, macOS, and visionOS that allows you to customize HTTP request headers such as Accept, Accept-Language, Cookie, and User-Agent. ChangeTheHeaders is available now in the App Store.

I owe the idea for ChangeTheHeaders—as well as its name—to John Gruber of Daring Fireball. John came to me with a Safari problem, presumably because I’m the person who claims to stop the madness in Safari. John was wondering why dragging an image to Finder directly from a web page (content warning: political) produced a WebP file, whereas dragging the image opened in a new Safari tab produced a PNG file. That is puzzling! After some investigation, I discovered that the difference was the Accept HTTP request header, which specifies what types of response the web browser will accept. Safari’s default Accept header for images is this:

Accept: image/webp,image/avif,image/jxl,image/heic,image/heic-sequence,video/*;q=0.8,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5

Although image/webp appears first in the list, the order actually doesn’t matter. The quality value, specified by the ;q= suffix, determines the ranking of types. The range of values is 0 to 1, with 1 as the default value if none is specified. Thus, image/webp and image/png have equal precedence, equal quality value 1, leaving it up to the web site to decide which image type to serve. In this case, the web site decided to serve a WebP image, despite the fact that the image URL has a .png suffix. In a URL, unlike in a file path, the “file extension”, if one exists, is largely meaningless. A very simple web server will directly match a URL with a local file path, but a more complex web server can do almost anything it wants with a URL.

What happens when you select “Open Image in New Tab” from the Safari contextual menu? The name of the contextual menu item is slightly misleading, because Safari doesn’t use the already loaded image but rather loads the image URL anew in a new tab. Moreover, for some reason, Safari uses a different Accept header in this case:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Given a different request header, the web site decided to return a different image type, PNG. Don’t ask me why, because I don’t know! Again, image/webp and image/png have equal precedence here, so you could receive either one (or some other image type). This is what computer programmers call “undefined behavior”.

You now have my typically long-winded explanation of the problem, but what’s my solution to the problem? The behavior is caused by the Accept header, so if you want to change the behavior, you have to change the header, and while Safari itself has no settings to change its HTTP request headers, it does provide that capability to Safari extensions, which is where I come in. I considered and rejected the idea of a “stop the webp images” extension as far too niche for a product. However, some StopTheMadness Pro customers have requested similar features, such as the ability to spoof the User-Agent header. Thus, I decided to make a Safari extension that can customize any HTTP request headers, in the hope that a market exists for it. (Alas, Safari does not allow customization of HTTP response headers too.)

You might ask, why didn’t I just add this feature to StopTheMadness Pro? On macOS, StopTheMadness Pro is a Safari app extension, but the API to modify HTTP headers is available only to Safari web extensions, unfortunately. This is the same reason that StopTheMadness Pro doesn’t currently support Safari web apps.

Originally, my name for the new Safari extension was the unimaginative Override Headers. As the old saying goes, there are only two hard things in computer science, and one of them is naming things. When I told John Gruber that I had trouble coming up with a good name for the extension, he immediately brainstormed ChangeTheHeaders, riffing on my theme of StopTheMadness, StopTheScript, StopTheFonts, etc. I liked and indeed preferred his suggestion, but the app was practically done already (or so I believed at the time). It already had an app icon, based on the old app name. On the other hand, that app icon was amateurish and poorly designed… by me! So I turned once again to a true professional, Matthew Skiles, for a new app icon, based on the new name. I tip my hat to Matt!

New Safari extension: ChangeTheHeaders to customize HTTP request headers

What can you do with ChangeTheHeaders? I suspect the biggest selling point will be to spoof the User-Agent. The extension allows you to customize your User-Agent by URL domain. For example, you can make Safari pretend that it’s Chrome on Google web apps that give special treatment to Chrome. You can also customize the Accept-Language header if you don’t like the default language handling of some website, such as YouTube. (Why is the problem on the web always Google?) Or if you just want to deprioritize WebP images in Safari, you can do that, of course. It’s a simple matter of removing image/webp from the list. You probably don’t want to stop WebP entirely, because it may be the only image type available on some websites, but if you remove image/webp from the Accept header, then it no longer has the default quality value of 1. Instead, image/webp would fall under the wildcard image/*;q=0.8 specification, with a lower priority than explicit image types such as image/png. More information on how to configure ChangeTheHeaders is in the fine manual.

I hope that you find ChangeTheHeaders useful. Get it now in the App Store!



Source link

Postagens Similares

  • Manton Reece – AI 支援リリースノート

    ネイティブ アプリはたくさんありますが、それを言い訳にして一般的な「バグ修正」のリリース ノートを書くつもりはありません。私は、ユーザーにとっても、出荷したものを後で振り返るときに自分自身にとっても、優れたリリース ノートを含めることが好きです。 それでも、続けなければならないことはたくさんあります。最近、私はリリース ノートのドラフトを作成するために Codex を利用しています。私は次のようなプロンプトを使用します。 「release/3.8.4」タグ以降のすべての git コミットを確認し、大きな変更点についてはリリース ノートを書いてください。ここの Web ページ help.micro.blog/t/micro-b… からリリース ノートを読み、何が重要で、変更をどのように表現するかについてそのスタイルに従ってください。 通常は完全に正しくはなく、少し冗長すぎるため、とにかく手書きで書いたものに合わせて編集できます。時間を大幅に節約できます。 Source link

  • डिफ़ॉल्ट जीवित या डिफ़ॉल्ट मृत?

    अक्टूबर 2015 जब मैं किसी ऐसे स्टार्टअप से बात करता हूं जो 8 या 9 महीने से अधिक समय से काम कर रहा है, तो पहली बात जो मैं जानना चाहता हूं वह लगभग हमेशा एक ही होती है। यह मानते हुए कि उनके खर्च स्थिर रहते हैं और उनकी राजस्व वृद्धि पिछले कई महीनों…

  • HazeOver — 用于突出显示最前面窗口的 Mac 实用程序

    2026 年 3 月 2 日星期一 早在 12 月,我就链接到了 Tyler Hall 的一个名为 Alan.app 的特技项目——一个简单的 Mac 实用程序,可以在当前活动窗口周围绘制一个粗体矩形。 Alan.app 允许您设置框架的厚度和颜色。我使用了一个小时左右,然后就退出了。它确实解决了在最新版本的 MacOS 中能够立即识别活动窗口的严重(且日益恶化)问题,但 Alan.app 的实现方式的粗糙性使其成为治本不如治病的情况之一。最终,我宁愿忍受几乎无法区分的活动窗口状态,也不愿每天看着 Alan.app 的原始活动窗口框架。 Alan.app 让我感兴趣的是它作为抗议应用程序的有效性。 Alan.app 的粗略解决方案的荒谬性凸显了根本问题的荒谬性——任何人甚至会 考虑 运行 Alan.app(或者 Hall 有意创建和发布它的事实)显示了最近的 MacOS 版本中的窗口 UI 有多么糟糕。 事实证明,有一个应用程序试图以一种您可能想要真正接受的优雅方式解决这个问题。它被称为 HazeOver,开发者 Maxim Ananov 在十年前首次发布了它。它在 Mac App Store 中的售价为 5 美元,包含在 SetApp 订阅服务中,并且可以从网站上免费试用。 HazeOver 的作用是通过调暗所有背景窗口来突出显示活动窗口。就是这样。但它能够沉着地完成这项简单的任务,并且对 MacOS 的日常可用性产生重大影响。不仅仅是 MacOS…

  • Constance Crozier:预测 S 曲线很困难

    哇,我们已经完成一半了吗?哇啊,生活在 S 曲线中 有一张著名的新冠疫情时期图表,我一直在努力寻找,它显示了在经历 S 曲线的过程中估计 S 曲线是多么困难。在早期,一切似乎都在呈指数爆炸式增长,你总是会收到一些炒作文章,说你,你这个笨蛋,不理解指数,让我解释一下。然后,当事情触及无形的渐近线时,那些写病毒式文章的同样响亮的声音奇怪地转向了其他事情。 不管怎样,下面的推文图片并不能体现这一点,你应该观看视频版本:https://vimeo.com/408599958 或 https://x.com/clcrozier/status/1251148890595708938 作者是康斯坦斯·克罗泽 (Constance Crozier),她还撰写了一篇博文。这是 googlebots 的完整内容: S 曲线(或 S 型函数)通常用于模拟社会或生物系统随时间的演变 (1)。这些函数从指数增长开始,然后线性增长,最后趋于平稳(因此最终看起来像一个不稳定的 s)。我们认为指数函数的许多东西实际上都遵循 S 曲线(否则系统将达到无穷大)。一个著名的例子是采用新技术。下图显示了随着时间的推移拥有智能手机的美国成年人的百分比,顶部有一条最适合的 S 曲线。在这种情况下,由于宣传和供应的推出方式,出现了指数增长。然而,潜在消费者数量有限(其中一些人永远不会拥有智能手机),因此增长逐渐放缓至零。 美国智能手机拥有量 (2) 另一个例子,也是这些曲线重新出现在新闻中的原因是疾病的传播。在这种情况下,当病毒是新病毒时,就会出现指数增长,因此大多数遇到它的人不会产生免疫力。之所以出现平稳,是因为病毒不再遇到没有免疫力的人(由于“群体免疫”或感染者的隔离)。下图显示了 2003 年 SARS 爆发期间中国的死亡人数,同样采用最佳拟合 S 曲线。 中国因非典死亡人数(3) S 曲线只有三个参数,因此它们如此适合各种系统,这也许令人印象深刻。概括地说,这三个参数描述了初始增长率、稳定率以及稳定值。因此,如果你能估计这三个数字,那么你就得到了趋势曲线。我们中的许多人都会在学校学到,如果要找到三个参数,则需要三个数据点来定义函数。这表明您可以仅根据三个观察结果完美地预测稳定点(剧透:您不能)。 实际上,虽然我们可以说数据的总体趋势可能符合某些 S 曲线,但各个点不会全部位于该曲线上。这可以在前面的两个例子中看到。这种差异通常被描述为“建模误差”,其中包括数据测量中的误差以及 S 曲线模型根本上错误的事实。引用乔治·博克斯的话:“所有模型都是错误的,但有些模型是有用的”。 直观上,从早期数据预测曲线是不可能的,这是有道理的。假设这一点意味着相信我们无法影响结果。然而,根据我的经验,“直觉”和“数学”往往很难调和。因此,我决定调查随着更多数据的出现,“最佳拟合 S 曲线”会发生多大变化。下面是我随机选择的 S 曲线。显示的点是“噪声观测值”——这是数学上表示“施加随机误差量的曲线上的点”的方式。 在这种情况下,S 曲线模型非常适合——我实际上是从 S 曲线生成数据的。这意味着如果误差为零,那么我们只需要三个点即可找到曲线。综上所述,这个例子是理想化的——现实中不太可能有一条曲线与数据如此吻合。下面的动画显示了随着更多数据的可用,最佳拟合 S 曲线(使用最小二乘优化找到)。 毫不奇怪,在指数增长阶段,估计非常糟糕,但即使在线性阶段(当有…

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *