-
Notifications
You must be signed in to change notification settings - Fork 876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When will json global variable be back #231
Comments
I've found a workaround for now - paste the following into your console: json = JSON.parse(document.getElementById("jsonFormatterRaw").querySelector("pre").innerText) |
Thanks, @ChrisBAshton ! |
The workaround provided by @ChrisBAshton works very well. I suggest the rep owner add this information on the README.md file as a suggestion while the global variation option is not available again. I'm glad I found this information here! :) |
Thanks all, just added that workaround to the readme. I'm not sure if it's possible to make it work again out of the box. I think the issue is there's now a stricter separation of contexts, so content scripts can't access the same |
One potential way of doing this would be to add a setInterval(() => {
debugger;
}, 500); Downside of this is that the page is no longer interactive. But you could measure how long it takes to 'execute' the debugger statement using const interval = setInterval(() => {
const then = performance.now()
debugger
if (performance.now() - then > 100) {
clearInterval(interval)
}
}, 500) |
Alternatively it seems like I did try the debugger statement though and that seems to work. |
Tampermonkey version that will automatically run on any // ==UserScript==
// @name JSON formatter `json` global
// @namespace https://github.com/lionel-rowe/
// @version 0.1
// @description try to take over the world!
// @author https://github.com/lionel-rowe/
// @match *://*/*.json
// @match *://*/*.json?*
// @icon https://www.google.com/s2/favicons?sz=64&domain=json.org
// @grant none
// ==/UserScript==
const el = document.querySelector('#jsonFormatterRaw pre');
if (el) window.json ??= JSON.parse(el.textContent); |
How did tampermonkey manage to work around the manifest changes? Are they still using manifest v2? |
Given Tampermonkey #644 [Chrome] Manifest V3: examine the effects is still open, I guess so. It looks like Google has delayed the retirement of v2, though it doesn't seem like there's currently a concrete updated timeline. |
@kykungz I don't think that would work. After all, if you can inject a button, why not just inject a |
Good point, I've never develop an extension before, so I'm not really sure how it works haha. For what it's worth, I tried attaching a click listener to a button, and yes, it does not work ( So I tried again by injecting the script right into the HTML attribute like this: const buttonInject = document.createElement('button')
buttonInject.innerText = 'Inject window.json'
buttonInject.setAttribute('onclick', `window.json = ${JSON.stringify(parsedJsonValue)}`)
optionBar.appendChild(buttonInject) and it seems to work. Does this change anything? Or it will only work locally? |
Content scripts can be injected in the main world by setting a manifest key. "content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"],
"run_at": "document_end",
+ "world": "MAIN"
}
], This hasn't been supported from the beginning, but I haven't found a clear answer to what Chrome version added support for this. Chrome Developers says the It is possible for webpages to interfere with these scripts, so caution should be taken when running a script in the main world on untrusted websites. Or, would a button to copy the JSON to the clipboard be a fine replacement? (related: #145) |
The README.md stated that:
But is there an estimated date that it will be back?
The text was updated successfully, but these errors were encountered: