Open Bug 1914978 Opened 1 year ago Updated 9 months ago

`webNavigation.onDOMContentLoaded` should preserve text fragments in `details.url`

Categories

(WebExtensions :: General, defect, P3)

Firefox 130
defect

Tracking

(firefox129 affected, firefox130 affected, firefox131 affected)

Tracking Status
firefox129 --- affected
firefox130 --- affected
firefox131 --- affected

People

(Reporter: sycxyc+mozilla, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Steps to reproduce:

  1. Enable dom.text_fragments.enabled on the about:config page.
  2. Load the "test_webnavigation-1.zip" temporary extension and open this extension console.
  3. Open "https://www.example.com/#hash:~:text=This-,domain,-is%20for%20use".

Actual results:

The extension console prints the url on the onDOMContentLoaded line as “https://www.example.com/#hash".

Expected results:

The extension console prints the url on the onDOMContentLoaded line as “https://www.example.com/#hash:~:text=This-,domain,-is%20for%20use".

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

Hello,

I reproduced the issue on the latest Nightly (131.0a1/20240827213859), Beta (130.0/20240826200919) and Release (129.0.2/20240819150008) under Windows 10 and macOS 11.3.1.

The issue occurs as described in Comment 0. See the attached screenshot for more details.

Status: UNCONFIRMED → NEW
Ever confirmed: true

Note that Chrome does include the text fragment in the URL in extension events, at least the given test case.

The question is what we should do here. Including the fragment enables extensions to detect the fragment and do something with it. But text fragments are hidden from scripts by design, so if an extension tries to correlate the URL as observed in the document (e.g. in a content script) with the URL as seen from extension, then that logic would break).

We retrieve the URL as documentURI at https://searchfox.org/mozilla-central/rev/55f2ada1564baaeebd69d277b38737961a3ca5f3/toolkit/components/extensions/webrequest/WebNavigationContent.cpp#119

Component: Untriaged → General

WebExtensions should need to be able to detect the fragment directive. I believe that preserving the fragment directive in the url is the simplest solution without altering the API design.

Because the fragment directive is preserved in browser history, the URL object, and <a> elements, compatibility issues may be hard to avoid.

The severity field is not set for this bug.
:robwu, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(rob)

(In reply to sycxyc+mozilla from comment #5)

WebExtensions should need to be able to detect the fragment directive.

What is the use case for that? With built-in support for text fragments, navigation to a text fragment is comparable to the user pasting the original URL and then jumping to some place in the page.

Severity: -- → S4
Flags: needinfo?(rob)
Priority: -- → P3

(In reply to Rob Wu [:robwu] from comment #7)

What is the use case for that?

Some extensions may need to read the full URL for purposes such as restoring the URL, handling text fragments, or interacting with the history and bookmarks APIs to perform certain actions.

The inconsistent behavior of webNavigation.onDOMContentLoaded may cause regression issues in the extension, requiring the implementation of additional compatibility logic.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: