This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to the original Chinese version. I am continuously working to improve the translation.
2025-05-14 Update: Due to a recent update from Bilibili, the Tampermonkey script no longer works—Bilibili has switched to Server Side Rendering (SSR), and video playback URLs are now embedded directly in the HTML. This means the request can no longer be intercepted by a userscript. Originally, this was just a personal script I wrote for my own use; I never expected so many people to find and use it via search engines. The script is now obsolete and will no longer be maintained. I’ve personally switched back to using the Fiddler method. This post is kept for educational purposes only.
My one-and-a-half-year Bilibili Premium membership recently expired, and honestly, I barely watched any anime—it was such a waste of money. Plus, new anime releases keep getting delayed, and the quality is all over the place (yes, I’m looking at you, The Three-Body Problem), so I have zero motivation to renew.
While browsing the web, I once came across something called a “Bilibili Premium video resolver.” In reality, it works by sharing a Premium account’s Cookie from a server, using it to access the video URL API, and then replacing the trial video on the webpage with the full version.
So I asked a friend to share their Premium account Cookie with me and tried to recreate this “resolver script” myself.
This approach doesn’t pollute others’ viewing history or recommendation algorithms, and I can still use my own account to send danmaku and comments.
First, I used F12 to inspect network traffic and found the API endpoint that fetches video playback URLs for anime. I used Fiddler to do a quick proof-of-concept to confirm this method still works.
A very simple script in the Fiddler Script editor can replace the Cookie for the target request:
1 | if (oSession.uriContains("pgc/player/web/v2/playurl")) { |
It worked—immediately, I could watch Premium-only videos using my own account. But having to keep Fiddler running just to browse Bilibili is pretty inconvenient. So I decided to turn this into a Tampermonkey script: https://gist.github.com/lyc8503/614f9d62c1b00175867fe0efc93c374f (if you have Tampermonkey, just click Raw to install)
Tampermonkey doesn’t natively support intercepting or modifying HTTP requests, so I had to manually hijack the XHR API. The code looks something like this:
1 | const oriSend = XMLHttpRequest.prototype.send |
I chose to use GM_xmlhttpRequest to make the actual request, which allows me to set anonymous: true to strip the original http-only Cookie and inject the Premium Cookie instead.
Bilibili also checks the Referer header, but that’s no issue for Tampermonkey—just pass the Referer in the headers parameter.
1 | GM_xmlhttpRequest({ |
However, GM_xmlhttpRequest‘s API differs slightly from the native XMLHttpRequest. For example, I had to manually assign the response body to the XHR object and ensure getAllResponseHeaders returns the correct result (otherwise Bilibili’s JavaScript would throw errors).
By setting breakpoints and stepping through the code, I identified all the problematic APIs and patched them. Some properties like responseText on the XHR object don’t have setters, so they can’t be directly modified. Instead, I used Object.defineProperty to forcibly override them:
1 | Object.defineProperty(this, 'statusText', { |
Finally, in the response data, there’s a need_vip field indicating whether a resolution is exclusive to Premium members. If left unchanged, I’d only be able to watch at 1080P or lower. Trying to switch to higher resolutions would still trigger the “Buy Premium” popup (since other API responses still show I’m not a Premium user).
But since I’m already hijacking the request, I can just search and replace the response to unlock all resolutions.
This article is licensed under the CC BY-NC-SA 4.0 license.
Author: lyc8503, Article link: https://blog.lyc8503.net/en/post/bilibili-share-vip/
If this article was helpful or interesting to you, consider buy me a coffee¬_¬
Feel free to comment in English below o/