Allow pretty printing and syntax highlight JS files which don't have Content-Type:"text/javascript" and don't end with .js/.jsm
Categories
(DevTools :: Debugger, defect, P2)
Tracking
(firefox45 affected)
Tracking | Status | |
---|---|---|
firefox45 | --- | affected |
People
(Reporter: arni2033, Unassigned)
References
Details
Attachments
(2 files)
STR: (Win7_64, Nightly 45, 32bit, ID 20151110030205, new profile) 1. Open attached "testcase 1" 2. Open devtools -> Debugger, click "Pretty print" button [{}] Result: The syntax isn't highlighted and JavaScript isn't pretty-printed at all. Console says > togglePrettyPrint threw an exception: Can't prettify non-javascript files. But I can debug such files if they are already properly formatted (with '\n's) Expectations: It should "syntax-highlighted" and pretty-printed normally: > var Div = document.querySelector('div'); > Div.addEventListener('click', function () { > console.log('click event'); > }, false);
Updated•9 years ago
|
Now here's funny thing: if I append "window.js" in the end of [src] in testcase 1, everything is OK
Updated•6 years ago
|
Comment 2•5 years ago
|
||
I was able to reproduce this bug using this STR:
- Load http://janodvarko.cz/tests/bugzilla/1224654/
- Open DevTools Toolbox and select the Debugger panel
- Expand
(no domain)
and select the only script there (it's data: URL) - There is no way to pretty print, there is not even a status bar with the pretty-print button
Is that because of the data: URL?
Honza
Updated•5 years ago
|
Comment 3•5 years ago
|
||
We presently have a function to test if we believe a file is reasonably JavaScript:
export function isJavaScript(source: Source, content: SourceContent): boolean {
const url = source.url;
const contentType = content.type === "wasm" ? null : content.contentType;
return (
(url && /\.(jsm|js)?$/.test(trimUrlQuery(url))) ||
!!(contentType && contentType.includes("javascript"))
);
}
This check is used before allowing pretty-printing a file. Maybe we remove this check and allow pretty-printing everything? Worst case scenario is a silent failure?
Updated•5 years ago
|
Comment 4•5 years ago
|
||
This is sill an issue. We could allow pretty-printing everything via:
diff --git a/devtools/client/debugger/src/actions/sources/prettyPrint.js b/devtools/client/debugger/src/actions/sources/prettyPrint.js
--- a/devtools/client/debugger/src/actions/sources/prettyPrint.js
+++ b/devtools/client/debugger/src/actions/sources/prettyPrint.js
@@ -41,9 +41,11 @@ export async function prettyPrintSource(
content: SourceContent,
actors: Array<SourceActor>
) {
+ /*
if (!isJavaScript(generatedSource, content) || content.type !== "text") {
throw new Error("Can't prettify non-javascript files.");
}
+ */
const url = getPrettySourceURL(generatedSource.url);
const { code, mappings } = await prettyPrint({
diff --git a/devtools/client/debugger/src/components/Editor/Footer.js b/devtools/client/debugger/src/components/Editor/Footer.js
--- a/devtools/client/debugger/src/components/Editor/Footer.js
+++ b/devtools/client/debugger/src/components/Editor/Footer.js
@@ -281,9 +281,7 @@ const mapStateToProps = state => {
selectedSource ? selectedSource.id : null
),
endPanelCollapsed: getPaneCollapse(state, "end"),
- canPrettyPrint: selectedSource
- ? canPrettyPrintSource(state, selectedSource.id)
- : false,
+ canPrettyPrint: !!selectedSource,
};
};
With that code, I try to pretty-print HTML, I get:
Error loading this URI: Invalid regular expression flag (3:115)
We we need to:
- Research a library that can handle pretty-printing multiple types of files
- Decide if these use cases are a priority.
Comment 5•5 years ago
|
||
It feels this issue throws together 3 issues:
- Enhancement: Pretty-print inline JS in HTML
- Pretty-print scripts in data: URL
- Missing pretty-print button on some obvious JS files (bug 1555307)
Which one would this bug tackle?
Updated•5 years ago
|
Comment 6•4 years ago
|
||
My proposal: Drop the fine-grained checks and show the pretty-printing button for all files that are not text/html (which we know for sure does not work).
Comment 7•2 years ago
|
||
Comment 8•2 years ago
|
||
Pretty print now works correctly for inline JS
Updated•2 years ago
|
Description
•