-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
history.pushState() error #20
Comments
Just realized that the current build at art-crawl-herokuapp.com does not have this problem, even if I attempt to replicate this issue. It is possible this problem comes from calling |
After testing current commit |
I think this is the problem: function changeImage(id) {
dataAttributes = getDataAttributes($(id));
img = $(id).find('img').attr('src').replace('thumbnails', 'artcrawl');
$('#metadata.active').css('opacity', 0);
setTimeout(function () {
$('#metadata-img').attr('src', img);
let loadedImg = document.querySelector('#metadata-img');
loadedImg.addEventListener('load', function(event) {
$('#metadata.active').css('opacity', 1);
renderMetadataImg($('#metadata-caption'), dataAttributes);
});
gridItemID = $('.art-crawl-item.highlight').attr('id');
let username = $('.art-crawl-item.highlight').attr('data-username');
history.pushState({'item_id': gridItemID}, 'Art Crawl', '#username=' + username + '&id=' + gridItemID);
handleGallery(window.location.hash.substr(1));
}, 550);
}
function handleGallery(hash) {
let params = getHashParams(hash);
let lastGridItem = document.querySelector('#grid').children.length - 2;
let gallery = parseInt(params.id);
$('.left').click(function() {
let highlights = Array.from(document.querySelectorAll('.highlight'));
for (let highlight of highlights) {
highlight.classList.remove('highlight');
}
gallery -= 1;
if (gallery < 0) {
gallery = lastGridItem;
}
changeImage('#' + gallery);
$('#' + gallery).addClass('highlight');
});
$('.right').click(function() {
let highlights = Array.from(document.querySelectorAll('.highlight'));
for (let highlight of highlights) {
highlight.classList.remove('highlight');
}
gallery += 1;
if (gallery > lastGridItem) {
gallery = 0;
}
changeImage('#' + gallery);
$('#' + gallery).addClass('highlight');
});
}
|
Resolved by removing the redundant firing. |
After adding gallery navigation, an error code appeared in the console.
In Firefox 83:
Uncaught DOMException: The operation is insecure.
Too many calls to Location or History APIs within a short timeframe.
In Safari 13.1.1:
SecurityError: Attempt to use history.pushState() more than 100 times per 30 seconds
Performance takes a massive hit once you start moving past those errors.
I might be able to fix by debouncing when
history.pushState()
fires. Say, fire only after if$('.left')
,$('.right'), and
$('.art-crawl-item')` are not clicked in such quick succession. The trick will be figuring out what constitutes 'too many clicks in succession.'The text was updated successfully, but these errors were encountered: