gpt4 book ai didi

google-chrome - Chrome 开发工具 : How to simulate offline for a particular domain than the entire network?

转载 作者:行者123 更新时间:2023-12-04 00:05:40 25 4
gpt4 key购买 nike

用例? Firebase有新产品 Firestore , 启用 offlinePersistence根据他们的文档。

https://firebase.google.com/docs/firestore/manage-data/enable-offline?authuser=0#listen_to_offline_data

我想测试一种情况,应用程序加载,但没有与 firebase 建立连接(想想具有 serviceworker 缓存静态 Assets 的 Progressive Web App),但没有连接到 Firebase 的网络。

我的代码看起来像

import React from "react";
import {fdb} from "../mainPage/constants";

// includeDocumentMetadataChanges to know when backend has written the local changes
// includeQueryMetadataChanges to know if changes come from cache using 'fromCache' property
// https://firebase.google.com/docs/firestore/manage-data/enable-offline?authuser=0#listen_to_offline_data
const queryOptions = {
includeDocumentMetadataChanges: true,
includeQueryMetadataChanges: true
};

const collectionName = "todos";
export default class ToDos extends React.Component {
constructor(props) {
super(props);
this.state = {
items: [],
textBox: "",
loading: true
}
}

componentWillMount() {
let unsubscribe = fdb.collection(collectionName)

.onSnapshot(queryOptions, function (querySnapshot) {
let items = [];
querySnapshot.forEach(function (doc) {
items.push(doc);
//console.log(" data: ", doc && doc.data());
});
this.setState({"items": items});
}.bind(this));
this.setState({"unsubscribe": unsubscribe});
}

componentWillUnmount() {
this.state.unsubscribe();
}

handleTextBoxChange = (event) => {
this.setState({textBox: event.target.value});
};

handleAddItem = () => {
fdb.collection(collectionName).add({
"title": this.state.textBox
}).then(function (docRef) {
//console.log("added " + docRef.id, docRef.get());
});
};

handleRemoveItem = (item) => {
console.log("Deleting: ", item.id);
item.ref.delete()
.then(function () {
console.log(item.id + " deleted successfully");
})
.catch(function(reason){
console.log(item.id + " failed to delete: ", reason);
})
};

render() {
return (
<div>
<div>
<input type="text" value={this.state.textBox} onChange={this.handleTextBoxChange}/>
<input type="submit" value="Add Item" onClick={this.handleAddItem}/>
</div>
<div>{this.state.items
.map((item, index) => <Item key={index}
item={item}
onDeleteClick={this.handleRemoveItem}/>)}</div>

</div>
)
}
}

const Item = ({item, onDeleteClick}) => {
let pendingWrite = item.metadata.hasPendingWrites ? "[PendingWrite]" : "[!PendingWrite]";
let source = item.metadata.fromCache ? "[Cache]" : "[Server]";
return <div>
<input type="button" value="delete" onClick={() => onDeleteClick(item)}/>
<span>{source + " " + pendingWrite + " " + item.data().title}</span>

</div>
};

问题
Chrome 开发者工具中有没有办法模拟/禁用对特定域的调用?

最佳答案

您正在寻找“请求阻止”功能。要使用它,请转到溢出菜单,然后单击“更多工具”,然后单击“请求阻止”。这会在抽屉中打开适当的面板以阻止对某个域或资源的请求。

查找菜单项。

locate request blocking

请求阻止面板。

request blocking in drawer

关于google-chrome - Chrome 开发工具 : How to simulate offline for a particular domain than the entire network?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46747745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com