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
Not running on about:blank #312
Comments
Chrome has a whitelist of URL schemes allowed for extensions: |
@tophf So you are saying that it is impossible? |
I'm just stating the facts. |
I wanted to use it to build a landingpage from scratch for a userscript. It modifies other sites, but I also want a page that is purely it's own. But if it can't be done, I'll find another solution. No problem. I just wanted to check. :) |
I'll probably publish a page somewhere and let the script modify that instead. |
I'd still like to be able to run userscripts in about:blank. Wouldn't this solve the problem: https://developer.chrome.com/extensions/content_scripts#match_about_blank |
@mold Yes, that looks to me like it should solve the problem. Out of curiosity: What is your use case? |
Hallo, I have also the problems to run scripts on about:blank. The use-case is, that a webpage opens a new Window with window.open('','...','toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, directories=yes, status=yes'); and puts html code into that opening window. This opens a page with "about.blank" and I wan't to modify this page. Knows anybody what I needs to do? |
Hi, I'm not sure if the |
Also interested in matching about:blank. I want to modify the background color to black so I can leave a low-RAM page open at night while using my other monitor, and not have it beaming white light into my face. This is in lieu of my just discovering that Custom.css user agent styling was removed from Chrome entirely: Tampermonkey would have been my next best solution:
I suppose I could simply not use about:blank but bookmark a local html file instead as a workaround. Just my two cents, anyway. |
@TomKrcmar those Custom.css and workarounds seem to be used to style the DevTools page but not about:blank. |
I think Custom.css was injected on all pages as an override to your User Agent Stylesheet, but had selectors for dev tools as well.
I have a dark theme selected already, but sadly my about:blank is still white.
Sorry, where's this customize button? My about:blank is completely blank, no button. |
It seems like the button is there if you set the search engine to Google. |
@7nik Oh I see what you're talking about, but that's on Either way, I support the ability to have Tampermonkey target these |
I also need this one feature. I'm working on a translation script, some web page use an inline iframe, like this: <!DOCTYPE html>
<html lang="en">
<head>
<title>iframe</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<article>
<p>This is a parent iframe</p>
</article>
<iframe src="frame.html" title="This is a child iframe"></iframe>
<iframe
srcdoc="<html><body><p>This is inline child frame,</p></html>"
></iframe>
</body>
</html> now, I can only inject to the first iframe, not the second inline iframe. so I can not translatae that. My script also offer a extension version, on the extension
This can work perfectly. |
I too have a need for this in order to have standalone user interfaces provided by userscripts. |
It seems people mostly want to open a page to display some info or userscript settings. But I don't see why they cannot do this on the current page (you can wrap everything into Shadow DOM to isolate it from the page). But I tried to make a workaround: // ==UserScript==
// @name Open a custom page
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author 7nik
// @match *://*/*
// @grant GM_registerMenuCommand
// @grant GM_openInTab
// ==/UserScript==
const html = `<html>
<head>
<title>My Title</title>
<style>h1{color:pink}</style>
</head>
<body>
<h1>My page</h1>
<p>This is my page</p>
<button id="btn">Action</button>
<script>
document.getElementById("btn").addEventListener("click", () => {alert("test"); window.opener?.postMessage("test"); });
window.addEventListener("message", (ev) => console.log(ev.data));
</script>
</body>`;
GM_registerMenuCommand("open page", () => {
// (1)
const blob = new Blob([html], { type: "text/html" });
const link = URL.createObjectURL(blob);
const w = window.open(link, "", "width=500,height=400");
URL.revokeObjectURL(link);
// comunication
window.addEventListener("message", (ev) => {
console.log(ev.data);
w.postMessage("Message was received");
});
// (2)
// to open only in a tab, no comunication
// GM_openInTab("data:text/html,"+html, { active: true });
// (3)
// re-using the current page
// document.documentElement.innerHTML = html;
// const scripts = document.querySelectorAll("script");
// for (let script of scripts) {
// const sc = document.createElement("script");
// for (let attr of script.attributes) {
// sc.setAttribute(attr.name, attr.value);
// }
// sc.textContent = script.textContent;
// script.parentElement.replaceChild(sc, script);
// }
}); The two first approaches are similar to iframe with srcdoc. But userscripts cannot run on such pages (and there is no localStorage access), though the first approach can use window messaging. The third approach just overrides the current page. So, if I really wanted to open a custom page, I'd open https://example.com and use the third approach to access GM_API. |
My workaround - created an extension.
content.js
|
In Greasemonkey you can run scripts on about:blank if you include it explicitly. However that does not seem to work in Tampermonkey. The following sample works with Greasemonkey but not with Tampermonkey.
The text was updated successfully, but these errors were encountered: