Closed Bug 1224654 Opened 9 years ago Closed 2 years ago

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)

defect

Tracking

(firefox45 affected)

RESOLVED INVALID
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);
Now here's funny thing: if I append "window.js" in the end of [src] in testcase 1, everything is OK
Summary: Pretty printing and syntax highlight don't work on JS loaded with <script src="data:, [...] "/> → Pretty printing and syntax highlight don't work on JS files which don't have Content-Type:"text/javascript" and don't end with .js/.jsm
Has STR: --- → yes
Depends on: 1224981
See Also: → 1258830
Product: Firefox → DevTools

I was able to reproduce this bug using this STR:

  1. Load http://janodvarko.cz/tests/bugzilla/1224654/
  2. Open DevTools Toolbox and select the Debugger panel
  3. Expand (no domain) and select the only script there (it's data: URL)
  4. 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

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?

No longer blocks: dbg-prettyprint

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:

  1. Research a library that can handle pretty-printing multiple types of files
  2. Decide if these use cases are a priority.
Blocks: dbg-72

It feels this issue throws together 3 issues:

  1. Enhancement: Pretty-print inline JS in HTML
  2. Pretty-print scripts in data: URL
  3. Missing pretty-print button on some obvious JS files (bug 1555307)

Which one would this bug tackle?

Flags: needinfo?(dwalsh)
Flags: needinfo?(dwalsh)
Summary: Pretty printing and syntax highlight don't work on JS files which don't have Content-Type:"text/javascript" and don't end with .js/.jsm → Allow pretty printing and syntax highlight JS files which don't have Content-Type:"text/javascript" and don't end with .js/.jsm

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).

Severity: normal → S3
Priority: P3 → P2
Attached image pretty-print.png

Pretty print now works correctly for inline JS

Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Resolution: FIXED → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: