-
Notifications
You must be signed in to change notification settings - Fork 13
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
InitData doesn't return correct values after page Refresh #18
Comments
Hi. Works correctly for me on Telegram Android. Can you reproduce it using Also, please provide more information. What Telegram client and version? Can you reproduce it on other clients? Which way do you launch the web app, from a keyboard button, from an inline button, from the bot menu button, via inline mode, from a direct link? |
Just tried with this code in Nuxt 3:
Also tried with
Both show the same initData result after refreshing. You can see it on screenshot below: FYI: Setting WebApp header color and background color works fine. But initData doesn't work. I am starting the app with Inline Button and it works fine on the first launch. The problem occurs only when I refresh the app from the "Refresh" button in the header. |
I temporarily resolved the issue by writing initData value into cookie on first launch and using this cookie after relaunch. But I believe it's not the best solution... |
Forgot to mention the Telegram versions: Latest version of TG on Windows (4.15). |
Can't reproduce on Windows either 🤔 |
Ok, got you. I will be digging into the issue when I have time. Thanks for assistance! |
I was able to reproduce. Nuxt uses "pages" directory for creating routes.
Without pages directory everything works fine. But when I add this directory the Refresh stops working. I don't know why. Maybe you can find a problem. BTW, Nuxt uses vue-router under the hood, so you don't need to install it with Nuxt3. |
Now I was able to reproduce the problem. I found out that something modifies the hash when the page loads. On the initial load, the hash contains the following:
Later, something (most likely Nuxt or vue-router, I'm not sure, maybe some sanitizer) changes the hash to:
After reloading the page, the modified hash remains, which breaks the parsing of hash in |
That's a much more complicated problem than I thought. Thanks for digging. I will think about how to fix. If I find a fix, I will comment. |
Hello, any news on that? |
I asked VueRouter team to disable hash encoding They said they are not planning to do this.
So we have what we have. |
Eh... Thanks Raxort, appreciate. I am using this way. Could you share with me how you use it in your application?
|
Hello, any news on that 💚 |
Hai, i am able to solve this by changing some lines in // from line 88 to 102
function urlParseQueryString(queryString) {
var params = {};
if (!queryString.length) {
return params;
}
var queryStringParams = []
if (queryString.indexOf('&tg') < 0) {
queryStringParams = queryString.split('&');
}
else {
queryStringParams = queryString.split(/&(?=tg)/);
}
var i, param, paramName, paramValue;
for (i = 0; i < queryStringParams.length; i++) {
param = queryStringParams[i].split(/=(.*)/s);
paramName = urlSafeDecode(param[0]);
paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
params[paramName] = paramValue;
}
return params;
} check above function, i used regex to split the string correctly and it worked. After editing, u can place this script: [
{
src: "/telegram-web-app.js",
defer: true,
},
], that's it :) |
WOW! Is it actually okay to use mine twa.js script in order to build telegram web app. Doesn't it check if used code the same? Can it lead to any security issues? |
Yes, it's okay to self-host the |
Still after modifying |
FWIW, I ended up using this in export default defineNuxtPlugin(() => {
const { hash } = location
const router = useRouter()
// If vue-router broke hash on init, restore it back.
// See https://github.com/deptyped/vue-telegram/issues/18
let needFixHash = router.currentRoute.value.hash !== hash
if (needFixHash) {
router.afterEach(() => {
if (needFixHash) {
location.hash = hash
needFixHash = false
}
})
}
}) |
The problem is in method: urlParseQueryString You can solve it replacing
TO
To Test in Console:
Let me know if it works for you. For us it solved sessions issue. |
Hey! Once again I need your assistance. I am building a webapp in Nuxt3. As you know, when you open a webapp in Telegram you can click on three dots in the header part and select "Refresh" the page. But after the refresh, InitData returns a string with value "query_id" and that's all...
So I have a question:
Is this a normal behavior that InitData doesn't return correct string after page refresh?
P.S.
Anyway, if the InitData is empty it should return null or undefined. But right now it returns "query_id".
The text was updated successfully, but these errors were encountered: