Error: Unsafe attempt to initiate navigation for frame with origin '' from frame with URL ''. The frame attempting navigation of the top-level window is sandboxed with the 'allow-top-navigation-by-user-activation' flag, but has no user activation (aka gesture). See .
Code:
function ModelViewer(token) {
if (!token) {
console.log("No token found");
return;
}
// Fetch the URL dynamically
google.script.run.withSuccessHandler(function (appUrl) {
console.log("Fetched URL:", appUrl);
google.script.run.withSuccessHandler(function (isValid) {
if (isValid) {
console.log("isValid it is!")
console.log("Token", token);
const link = document.createElement('a');
link.href = `${appUrl}?page=Models&token=${token}`;
link.id = 'linkURL';
document.body.appendChild(link);
document.getElementById('linkURL').click();
} else {
console.log("isValid",isValid);
console.log("Token", token);
console.log("Invalid token. Redirecting to SignIn.");
showNotification("Session expired. Please sign in again.", "error");
}
}).validateToken(token);
}).getAppUrl(); // Call the server-side function to get the URL
}
Error: Unsafe attempt to initiate navigation for frame with origin 'https://script.google' from frame with URL 'https://n-x4qqieogl32dh7vitgxnysfogdq2h5ccinv5p6a-0lu-script.googleusercontent/userCodeAppPanel'. The frame attempting navigation of the top-level window is sandboxed with the 'allow-top-navigation-by-user-activation' flag, but has no user activation (aka gesture). See https://www.chromestatus/feature/5629582019395584.
Code:
function ModelViewer(token) {
if (!token) {
console.log("No token found");
return;
}
// Fetch the URL dynamically
google.script.run.withSuccessHandler(function (appUrl) {
console.log("Fetched URL:", appUrl);
google.script.run.withSuccessHandler(function (isValid) {
if (isValid) {
console.log("isValid it is!")
console.log("Token", token);
const link = document.createElement('a');
link.href = `${appUrl}?page=Models&token=${token}`;
link.id = 'linkURL';
document.body.appendChild(link);
document.getElementById('linkURL').click();
} else {
console.log("isValid",isValid);
console.log("Token", token);
console.log("Invalid token. Redirecting to SignIn.");
showNotification("Session expired. Please sign in again.", "error");
}
}).validateToken(token);
}).getAppUrl(); // Call the server-side function to get the URL
}
Share
Improve this question
edited Nov 21, 2024 at 7:45
TheMaster
50.9k7 gold badges70 silver badges99 bronze badges
asked Nov 20, 2024 at 17:57
DhruvDhruv
133 bronze badges
1
|
1 Answer
Reset to default 0As the sandbox name, allow-top-navigation-by-user-activation'
says, you can't navigate to another page without a user interaction. The link needs to clicked by the end user with the target attribute set to the top frame.
const link = document.createElement('a');
link.href = `${appUrl}?page=Models&token=${token}`;
link.id = 'linkURL';
link.target = '_top'
link.innerText = 'Signed in! Click Here to continue!'
document.body.appendChild(link); //No auto click possible
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742339427a4425320.html
windows.open("enter-your-link")
– Gyul Commented Nov 21, 2024 at 21:16