Closed Bug 1678987 Opened 4 years ago Closed 3 years ago

View -> Page Style menu is broken after changes in document.styleSheets

Categories

(Firefox :: Menus, defect, P1)

Firefox 83
defect

Tracking

()

RESOLVED FIXED
85 Branch
Tracking Status
firefox-esr78 --- wontfix
firefox83 --- wontfix
firefox84 --- wontfix
firefox85 --- fixed

People

(Reporter: siemenskun, Assigned: emilio)

References

(Regression)

Details

(Keywords: regression)

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0

Steps to reproduce:

Press Alt key on any site with alternative stylesheets (e.g. https://iichan.hk/b/).
Choose View -> Page Style. You can't select alternative stylesheets - there aren't any.

It's a regression due to removing disabled stylesheets from document.styleSheets for consistency with weird Blink/Webkit behavior. (https://github.com/whatwg/html/issues/3840) But this menu relies on the assumption that document.styleSheets contains all available stylesheets on the page.

Actual results:

The menu displays only currently selected stylesheet and No Style.

Expected results:

The menu should display all alternative stylesheets.

Component: Untriaged → Menus
See Also: → 1494587

So the relevant code is this:

function set_stylesheet(styletitle,target)
{
	set_cookie("wakabastyle",styletitle,365);

	var links = target ? target.document.getElementsByTagName("link") : document.getElementsByTagName("link");
	var found=false;
	for(var i=0;i<links.length;i++)
	{
		var rel=links[i].getAttribute("rel");
		var title=links[i].getAttribute("title");
		if(rel.indexOf("style")!=-1&&title)
		{
			links[i].disabled=true; // IE needs this to work. IE needs to die.
			if(styletitle==title) { links[i].disabled=false; found=true; }
		}
	}
	if(!found)
	{
		if(target) set_preferred_stylesheet(target);
		else set_preferred_stylesheet();
	}
}

function set_preferred_stylesheet(target)
{
	var links = target ? target.document.getElementsByTagName("link") : document.getElementsByTagName("link");
	for(var i=0;i<links.length;i++)
	{
		var rel=links[i].getAttribute("rel");
		var title=links[i].getAttribute("title");
		if(rel.indexOf("style")!=-1&&title) links[i].disabled=(rel.indexOf("alt")!=-1);
	}
}

If instead of links[i].disabled the page would use links[i].sheet?.disabled, then it'd work as before.

I think this is kind of expected given the changes in bug 1281135. But we could tweak this menu to look at those links as well, potentially.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Regressed by: 1281135
Has Regression Range: --- → yes

I can try to poke when I have some time, though this is probably not super-high priority.

The relevant code lives in browser/actors/PageStyleChild.jsm, and I think it should be relatively easy to handle this case, if someone wants to steal I'd appreciate it :-)

Flags: needinfo?(emilio)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #1)

If instead of links[i].disabled the page would use links[i].sheet?.disabled, then it'd work as before.

And it'd stop work in Blink :)

Hmm, Blink should've fixed to match our behavior already iiuc. But yeah it'd stop working in WebKit I guess.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #4)

Hmm, Blink should've fixed to match our behavior already iiuc. But yeah it'd stop working in WebKit I guess.

Chrome 87, works only if links were toggled from DOM beforehand (link.disabled = true; link.disabled = false). Then you can switch styles through link.sheet.disabled. But in case of the DOM attribute I can manipulate it right after <link> tag appeared in the DOM tree, and for link.sheet I have to wait until the stylesheets are loaded, and only then I can toggle them. (link.sheet is null while they are loading)
For example, if I have to switch the style to a user-selected one by javascript in browser while page loading (e.g. by cookie), the user at first will see the page with default stylesheet applied and only then in the selected one, because the safe time when I can toggle link.sheet.disabled in only after onload event.
If I toggle stylesheets using link.disabled, user will see preferred stylesheet without "blinking" with standard one, because I don't have to wait onload event in this case.
So, using link.sheet.disabled is definitely inconvenient, and link.disabled can't be safely replaced to link.sheet.disabled.

Blocks: 1679160

<link disabled> doesn't appear in document stylesheets, but some pages
use it to use alternative stylesheets.

Assignee: nobody → emilio
Status: NEW → ASSIGNED
No longer blocks: 1679160
Depends on: 1679160
Flags: needinfo?(emilio)
Severity: -- → S3
Priority: -- → P1
Pushed by ealvarez@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/5e796e573157
Make page style menu deal with <link disabled> better. r=mconley
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 85 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: