fix(common): ensure scrollRestoration is writable (#30630)
Some specialised browsers that do not support scroll restoration (e.g. some web crawlers) do not allow `scrollRestoration` to be writable. We already sniff the browser to see if it has the `window.scrollTo` method, so now we also check whether `window.history.scrollRestoration` is writable too. Fixes #30629 PR Close #30630
This commit is contained in:

committed by
Andrew Kushnir

parent
8227b56f9e
commit
bb88c9fa3d
@ -23,10 +23,25 @@ import {BrowserViewportScroller, ViewportScroller} from '../src/viewport_scrolle
|
||||
describe('BrowserViewportScroller', () => {
|
||||
let scroller: ViewportScroller;
|
||||
let documentSpy: any;
|
||||
let windowSpy: any;
|
||||
|
||||
beforeEach(() => {
|
||||
windowSpy = jasmine.createSpyObj('window', ['history']);
|
||||
windowSpy.scrollTo = 1;
|
||||
windowSpy.history.scrollRestoration = 'auto';
|
||||
|
||||
documentSpy = jasmine.createSpyObj('document', ['querySelector']);
|
||||
scroller = new BrowserViewportScroller(documentSpy, {scrollTo: 1}, null!);
|
||||
scroller = new BrowserViewportScroller(documentSpy, windowSpy, null!);
|
||||
});
|
||||
|
||||
it('should not crash when scrollRestoration is not writable', () => {
|
||||
Object.defineProperty(windowSpy.history, 'scrollRestoration', {
|
||||
value: 'auto',
|
||||
configurable: true,
|
||||
});
|
||||
expect(() => scroller.setHistoryScrollRestoration('manual')).not.toThrow();
|
||||
});
|
||||
|
||||
it('escapes invalid characters selectors', () => {
|
||||
const invalidSelectorChars = `"' :.[],=`;
|
||||
// Double escaped to make sure we match the actual value passed to `querySelector`
|
||||
|
Reference in New Issue
Block a user