19.2.16日报:script的文本解码流程

起源是https://zhitongche.taobao.com/ 有个url(g.alicdn.com/kissy/k/1.4.4/seed.js)老是解码错误。

原因是阿里的垃圾程序员,在url里明明写着是GBK的页面,js却是utf-8编码。

blink会在下面堆栈里预加载js:

blink::TextResource::TextResource(const blink::Resou blink::ScriptResource::ScriptResource(const blink::R blink::ScriptResource::ScriptResourceFactory::create blink::ResourceFetcher::createResourceForLoading(bli blink::ResourceFetcher::requestResource(blink::Fetch blink::ScriptResource::fetch(blink::FetchRequest & r blink::DocumentLoader::startPreload(blink::Resource: blink::HTMLResourcePreloader::preload(WTF::PassOwnPt blink::ResourcePreloader::takeAndPreload(WTF::Vector blink::HTMLDocumentParser::processParsedChunkFromBac blink::HTMLDocumentParser::pumpPendingSpeculations() blink::HTMLDocumentParser::resumeParsingAfterYield() blink::HTMLParserScheduler::continueParsing() 行 169

然后会在

node.dll!blink::ScriptLoader::fetchScript(const WTF::String  node.dll!blink::ScriptLoader::prepareScript(const WTF::TextP node.dll!blink::HTMLScriptRunner::runScript(blink::Element * node.dll!blink::HTMLScriptRunner::execute(WTF::RawPtr<blink: node.dll!blink::HTMLDocumentParser::runScriptsForPausedTreeB node.dll!blink::HTMLDocumentParser::processParsedChunkFromBa node.dll!blink::HTMLDocumentParser::pumpPendingSpeculations( node.dll!blink::HTMLDocumentParser::resumeParsingAfterYield( node.dll!blink::HTMLParserScheduler::continueParsing() 行 16 node.dll!WTF::FunctionWrapper<void (__thiscall blink::HTMLPa

里真正去加载js。但会在ResourceFetcher::requestResource里,因为第一次预加载了,所以只会取出request去用。

我打算在这两个地方做个hook,把这个url强制改成utf-8解码。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券