我开发了一个SharePoint WebPart,在Teams中作为应用程序使用。在这个WebPart中,我调用一个外部站点(http:/xxxxexample.html)来存储一些数据与indexedDB。
public async render() {
this.domElement.innerHTML = `<iframe src="http://xxxx/example.html?token=xxxxxxxx"/>`;
}
如果我尝试在Chrome、Firefox......和桌面应用程序中使用这个应用程序,所有的工作都很正常,但我发现当我尝试在Android应用程序中使用Teams时出现了一个错误。
我可以做什么来使用android应用程序中的indexedDB for Teams?
这是外部网站的代码(http:/xxxxexample.html),我从WebPart中调用。
如果我尝试在Android应用中使用Teams应用,我就会出现以下错误。
'为了应用程序的正确运行,必须允许访问IndexedDB'。
在其他情况下。桌面应用,使用导航器... 工作正常。从我的角度来看是相对于Android App处理indexedDB的方式。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example</title>
</head>
<body>
<script>
var tableName = '_test';
var key = 'a2B2MSmQa1';
var mydb;
var entry = getEntry();
var stringEntry = JSON.stringify(entry);
function getEntry() {
// prepare authentication info
var token = findGetParameter('token');
var user = getUserFromJwt(token);
console.log('Received request to log in with token: ' + token + ' and user: ' + user);
return [{
"AnyeP3Hy11": btoa(user),
"bcdW7Sibfo": "",
"AE1RLE62l3": true,
"Tx22M4zx51": btoa(token),
"1l2i483Zx5": false
}];
}
function getUserFromJwt(token) {
var payload = token.split('.')[1];
var claims = JSON.parse(atob(payload));
return claims.email;
}
function saveTokenDataWebSql() {
mydb.transaction(function (t) {
t.executeSql('select * from ' + tableName + ' where key = ?', [key], function (transaction, data) {
if (!data.rows.length) {
// if authentication info doesn't already exists -> create it it
mydb.transaction(function (t) {
t.executeSql('insert into ' + tableName + '(key, value) values (?, ?)', [key, stringEntry], goToApp);
console.log('Inserted entry');
});
} else {
// if authentication info already exists -> replace it
mydb.transaction(function (t) {
t.executeSql('update ' + tableName + ' set value = ? where key = ?', [stringEntry, key], goToApp);
console.log('Updated entry');
});
}
});
});
}
function saveTokenDataIndexedDB(objectStore) {
objectStore.count(key).onsuccess = function (event) {
var count = event.target.result;
if (count !== 0) {
// if authentication info already exists -> remove it
objectStore.delete(key).onsuccess = function () {
// save auth info after deletion
objectStore.put(entry, key);
};
} else {
// save auth info directly
objectStore.put(entry, key);
}
};
}
var indexedDBWay = function () {
console.log('Using indexedDB option');
var request = indexedDB.open('__mydb', 2);
request.onerror = function (event) {
alert('It is necessary for the correct functioning of the app to allow access to IndexedDB.');
};
request.onsuccess = function (event) {
mydb = event.target.result;
try {
console.log('Database opened, checking existence of table');
var objectStore = mydb.transaction([tableName], 'readwrite')
.objectStore(tableName);
console.log('Table exists. Proceeding to save data');
saveTokenDataIndexedDB(objectStore);
console.log('All done, going to app');
goToApp();
} catch (e) {
console.log(e);
}
};
};
var openDatabaseWay = function () {
console.log('Using openDatabase option');
mydb = openDatabase('__mydb', '1', 'desc', 1024 * 1024);
console.log('Database opened, checking existence of table');
mydb.transaction(function (t) {
t.executeSql('select * from ' + tableName, [], function (transaction, data) {
if (data.rows) {
console.log('Table exists. Proceeding to save data');
saveTokenDataWebSql();
} else {
console.error('App DB not present, go back to app');
goToApp();
}
}, function (t, e) {
console.log('Error while opening database', e);
console.log('Creating database');
createWebSqlDbTable(t, tableName, function () {
openDatabaseWay();
}, function (t, e) {
console.log('Error while creating database. All hope is lost.', e);
goToApp();
})
});
});
};
function createWebSqlDbTable(t, tableName, callback, errorCallback) {
t.executeSql(
'CREATE TABLE IF NOT EXISTS ' + tableName +
'(id INTEGER PRIMARY KEY, key unique, value)',
[],
callback,
errorCallback
);
}
console.log('Trying to save token data');
var debug = location.search.indexOf('debug') !== -1;
if(debug){
debugger;
}
if (window.openDatabase) {
openDatabaseWay();
} else if (window.indexedDB) {
indexedDBWay();
} else {
console.error('Cannot open database, go back to app');
goToApp();
}
</script>
</body>
</html>
谁能给我一些线索?
谢谢
Android在WebView上加载应用。WebViews不像完全的浏览器那样具有强大的功能。必须看看WebViews是否完全支持indexDB。
https:/caniuse.com#search=indexDB. 这说明IndexDB是支持Chrome for Android 81+的。你可以检查webview上显示的chrome版本。这又是取决于手机。(使用chrome:/inspect从笔记本chrome浏览器,而你的手机是可以调试和连接的)
也可能是权限的问题。不过我不确定。我在某个地方读到过这个。为了排除这种情况,你可以尝试通过手动提供存储权限给Teams应用来验证它是否解决了这个问题?
如果这些都没有帮助,很可能是WebView的问题,或者Teams必须做一些事情来启用indexDB,如果WebView支持的话。