Skip to content

Commit

Permalink
Fix up line numbers etc
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishwillee committed Sep 20, 2024
1 parent 1db81ba commit c2b0731
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
17 changes: 12 additions & 5 deletions files/en-us/web/api/cspviolationreportbody/columnnumber/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,30 @@ Note that while there might be multiple reports in the returned array, for brevi

#### Results

If serving the above code using a local server (on `http://127.0.0.1:9999/`), the output of the log on Chrome is:
You can try this out using a [local server](/en-US/docs/Learn/Common_questions/Tools_and_setup/set_up_a_local_testing_server).
Copy the above code into `test/index.html` and `test/main.js` and run the server in the root directory.
Assuming the address of the local server is `http://127.0.0.1:9999`, you can then load the HTML file from `http://127.0.0.1:9999/test/` (or `http://127.0.0.1:9999/test/index.html`).

With the above setup, the output of the log on Chrome is:

```plain
sourceFile: http://127.0.0.1:9999/test/
lineNumber: 17
lineNumber: 15
columnNumber: 0
```

Note that the column number is (incorrectly) set to `0`.
The result is similar for Firefox, which correctly reports the `columnNumber`.
The result is similar for Firefox:

```plain
sourceFile: http://127.0.0.1:9999/test/
lineNumber: 17
lineNumber: 15
columnNumber: 13
```

Note that the column number is different for the two browsers.
Chrome always appears to report `0`.
The value on Firefox appears to point to the second character after the end of the opening `<script>` element.

## Specifications

{{Specifications}}
Expand Down
23 changes: 13 additions & 10 deletions files/en-us/web/api/cspviolationreportbody/linenumber/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This example triggers a CSP violation using an inline script, and reports the vi

#### HTML

The HTML file below uses the [`<meta>`](/en-US/docs/Web/HTML/Element/meta) element to set the {{httpheader('Content-Security-Policy')}} `default-src` to `self`, which allows scripts and other resources to be loaded from the same domain, but does not allow inline scripts to be executed.
The HTML file below uses the [`<meta>`](/en-US/docs/Web/HTML/Element/meta) element to set the {{httpheader('Content-Security-Policy')}} `default-src` to `self`, which allows scripts and other resources to be loaded from the same origin, but does not allow inline scripts to be executed.
The document also includes an inline script, which should therefore trigger a CSP violation.

```html
Expand All @@ -53,8 +53,6 @@ The document also includes an inline script, which should therefore trigger a CS
</html>
```

Copy the above code into a file `test/index.html`.

#### JavaScript (main.js)

The document above also loads the external script `main.js`, which is shown below.
Expand Down Expand Up @@ -83,27 +81,32 @@ observer.observe();

Note that while there might be multiple reports in the returned array, for brevity we only log the values of the first element.

Copy the code above into `test/main.js` alongside the `index.html` file.

#### Results

If using a local server to load the HTML from `http://127.0.0.1:9999/test/` (or `http://127.0.0.1:9999/test/index.html`), the output of the log on Chrome is:
You can try this out using a [local server](/en-US/docs/Learn/Common_questions/Tools_and_setup/set_up_a_local_testing_server).
Copy the above code into `test/index.html` and `test/main.js` and run the server in the root directory.
Assuming the address of the local server is `http://127.0.0.1:9999`, you can then load the HTML file from `http://127.0.0.1:9999/test/` (or `http://127.0.0.1:9999/test/index.html`).

With the above setup, the output of the log on Chrome is:

```plain
sourceFile: http://127.0.0.1:9999/test/
lineNumber: 17
lineNumber: 15
columnNumber: 0
```

Note that the column number is (incorrectly) set to `0`.
The result is similar for Firefox, which correctly reports the `columnNumber`.
The result is similar for Firefox:

```plain
sourceFile: http://127.0.0.1:9999/test/
lineNumber: 17
lineNumber: 15
columnNumber: 13
```

Note that the column number is different for the two browsers.
Chrome always appears to report `0`.
The value on Firefox appears to point to the second character after the end of the opening `<script>` element.

## Specifications

{{Specifications}}
Expand Down
19 changes: 13 additions & 6 deletions files/en-us/web/api/cspviolationreportbody/sourcefile/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This example triggers a CSP violation using an inline script, and reports the vi

#### HTML

The HTML file below uses the [`<meta>`](/en-US/docs/Web/HTML/Element/meta) element to set the {{httpheader('Content-Security-Policy')}} `default-src` to `self`, which allows scripts and other resources to be loaded from the same domain, but does not allow inline scripts to be executed.
The HTML file below uses the [`<meta>`](/en-US/docs/Web/HTML/Element/meta) element to set the {{httpheader('Content-Security-Policy')}} `default-src` to `self`, which allows scripts and other resources to be loaded from the same origin, but does not allow inline scripts to be executed.
The document also includes an inline script, which should therefore trigger a CSP violation.

```html
Expand Down Expand Up @@ -86,23 +86,30 @@ Note that while there might be multiple reports in the returned array, for brevi

#### Results

If serving the above code using a local server (on `http://127.0.0.1:9999/`), the output of the log on Chrome is:
You can try this out using a [local server](/en-US/docs/Learn/Common_questions/Tools_and_setup/set_up_a_local_testing_server).
Copy the above code into `test/index.html` and `test/main.js` and run the server in the root directory.
Assuming the address of the local server is `http://127.0.0.1:9999`, you can then load the HTML file from `http://127.0.0.1:9999/test/` (or `http://127.0.0.1:9999/test/index.html`).

With the above setup, the output of the log on Chrome is:

```plain
sourceFile: http://127.0.0.1:9999/test/
lineNumber: 17
lineNumber: 15
columnNumber: 0
```

Note that the column number is (incorrectly) set to `0`.
The result is similar for Firefox, which correctly reports the `columnNumber`.
The result is similar for Firefox:

```plain
sourceFile: http://127.0.0.1:9999/test/
lineNumber: 17
lineNumber: 15
columnNumber: 13
```

Note that the column number is different for the two browsers.
Chrome always appears to report `0`.
The value on Firefox appears to point to the second character after the end of the opening `<script>` element.

## Specifications

{{Specifications}}
Expand Down

0 comments on commit c2b0731

Please sign in to comment.