最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can my extension's Content Script change the value of a script variable before the page reads it? - Sta

programmeradmin2浏览0评论

I am writing an extension and using "world": "MAIN" in the manifest for my content script, and I want to be able to modify a variable in the source code before the page accesses it.

My specific use case: The source page contains an inline script:

<script type="text/javascript">
    window.gameData = {…}
</script>

where window.gameData is

{
"today":
{
"displayWeekday":"Thursday",
"outerLetters":["d","g","i","l","y","z"],
"answers":["dizzyingly","diddling","digging",…],
"id":18831,
…
},

"yesterday":
{
"displayWeekday":"Wednesday",
"outerLetters":["a","c","e","l","n","o"],
"answers":["conclave","covalence","alcove",…],
"id":16175,
…
},
…
}

I want to change the array at: window.gameData.today.answers before the page reads it.

Using Chrome DevTools, I located the spot in the page's script where the value is read, but I don't know how to determine when this occurs, and how to get in earlier than that. Here is where the value is read:

65489: function (e, t, n) {
n.d(t, {
    $g: function () { return s.$g },
    Be: function () { return _.B }
});
var r = n(74395)
    , o = n(22042);
if ((0, p.Z)(), o.G7)
    f.win.dataLayer = [];
else {
    const e = (0, i.pg)();
    e || ((0, i.He)()),
        f.win.addEventListener("load", (() => {
            (0, u.IX)()
        }))
}
const x = () => f.win.gameData
},

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论