Bug 1659155 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

Since bug 1452819, the `info.srcUrl` field of the `contextMenus.onClicked` event returns the URL after redirects, instead of the URL of the image request.

Prior to that bug, and also in Chrome, the `info.srcUrl` field was the image's src element.

STR:
1. Load attached extension, which opens a tab with an image.
2. Right-click on the image and click on the extension's context menu.

Expected (Chrome 84):
- A dialog with a URL ending with "before-redirect".

Actual (Firefox 81):
- A dialog with a URL ending with "after-redirect"

I'm inclined to resolve the bug as follows:

- Update MDN to clarify that `info.srcUrl` may differ from the `<img>`'s src attribute. In Chrome, this is always the URL of the initial request. In Firefox, this is the final URL (after any redirects).
- Add a unit test to make sure that the behavior continues to be as documented.

The alternative is to let `info.srcUrl` be the initial URL again. This would result in consistent behavior between Firefox and Chrome. I guess that few users cared either way, since nobody has filed a bug about this (I only discovered this when I [investigated a report about DownThemAll not working on Twitter](https://bugzilla.mozilla.org/show_bug.cgi?id=1621249#c4)).

Some extensions ([including DownThemAll](https://github.com/downthemall/downthemall/blob/858b8f277e8f9c0a080193916c6f01c73aa437a0/lib/background.ts#L505-L531)) use `info.srcUrl` to identify the element to which the context menu is anchored from a content script. Since there is a superior alternative (`info.targetElementId` + [`browser.menus.getTargetElement`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/getTargetElement)), I would recommend extension authors to use that API to really identify the target element without having to traverse the whole DOM to find the image element of interest.
Since bug 1406253, the `info.srcUrl` field of the `contextMenus.onClicked` event returns the URL after redirects, instead of the URL of the image request.

Prior to that bug, and also in Chrome, the `info.srcUrl` field was the image's src element.

STR:
1. Load attached extension, which opens a tab with an image.
2. Right-click on the image and click on the extension's context menu.

Expected (Chrome 84):
- A dialog with a URL ending with "before-redirect".

Actual (Firefox 81):
- A dialog with a URL ending with "after-redirect"

I'm inclined to resolve the bug as follows:

- Update MDN to clarify that `info.srcUrl` may differ from the `<img>`'s src attribute. In Chrome, this is always the URL of the initial request. In Firefox, this is the final URL (after any redirects).
- Add a unit test to make sure that the behavior continues to be as documented.

The alternative is to let `info.srcUrl` be the initial URL again. This would result in consistent behavior between Firefox and Chrome. I guess that few users cared either way, since nobody has filed a bug about this (I only discovered this when I [investigated a report about DownThemAll not working on Twitter](https://bugzilla.mozilla.org/show_bug.cgi?id=1621249#c4)).

Some extensions ([including DownThemAll](https://github.com/downthemall/downthemall/blob/858b8f277e8f9c0a080193916c6f01c73aa437a0/lib/background.ts#L505-L531)) use `info.srcUrl` to identify the element to which the context menu is anchored from a content script. Since there is a superior alternative (`info.targetElementId` + [`browser.menus.getTargetElement`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/getTargetElement)), I would recommend extension authors to use that API to really identify the target element without having to traverse the whole DOM to find the image element of interest.
Since bug 1406253, the `info.srcUrl` field of the `contextMenus.onClicked` event returns the URL after redirects, instead of the URL of the image request.

Prior to that bug, and also in Chrome, the `info.srcUrl` field was the image's src element.

STR:
1. Load attached extension, which opens a tab with an image.
2. Right-click on the image and click on the extension's context menu.

Expected (Chrome 84):
- A dialog with a URL ending with "before-redirect".

Actual (Firefox 81):
- A dialog with a URL ending with "after-redirect"

I'm inclined to resolve the bug as follows:

- ~Update MDN to clarify that `info.srcUrl` may differ from the `<img>`'s src attribute. In Chrome, this is always the URL of the initial request. In Firefox, this is the final URL (after any redirects).~ EDIT: The alternative is preferred, see comment 2 and comment 3.
- Add a unit test to make sure that the behavior continues to be as documented.

The alternative is to let `info.srcUrl` be the initial URL again. This would result in consistent behavior between Firefox and Chrome. I guess that few users cared either way, since nobody has filed a bug about this (I only discovered this when I [investigated a report about DownThemAll not working on Twitter](https://bugzilla.mozilla.org/show_bug.cgi?id=1621249#c4)).

Some extensions ([including DownThemAll](https://github.com/downthemall/downthemall/blob/858b8f277e8f9c0a080193916c6f01c73aa437a0/lib/background.ts#L505-L531)) use `info.srcUrl` to identify the element to which the context menu is anchored from a content script. Since there is a superior alternative (`info.targetElementId` + [`browser.menus.getTargetElement`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/getTargetElement)), I would recommend extension authors to use that API to really identify the target element without having to traverse the whole DOM to find the image element of interest.

Back to Bug 1659155 Comment 0