@Pallas I'm trying to display a Modal on the center of the page, what I should do on the style.css?
@Pallas I'm trying to display a Modal on the center of the page, what I should do on the style.css?
top and left values to change the starting position of the modal. chrome.runtime.connect method, which is used to establish a connection between different parts of your extension. Make sure that you're using this method correctly and that you're passing in the correct parameters. chrome.runtime.onMessage.addListener and chrome.runtime.connect are both methods used for communication between different parts of a Chrome extension. However, they have different use cases and behaviors.chrome.runtime.onMessage.addListener is used for communication between content scripts and background scripts. Content scripts are scripts that run in the context of a web page, while background scripts run in the background of the extension. When a content script wants to send a message to the background script, it uses chrome.runtime.sendMessage, and the background script listens for these messages using chrome.runtime.onMessage.addListener. chrome.runtime.connect is used for communication between different parts of the background script. For example, if you have a background script that is split into multiple files, you can use chrome.runtime.connect to establish a connection between them and pass messages back and forth.chrome.runtime.onMessage.addListener instead of chrome.runtime.connect, it could mean that you are trying to communicate between a content script and a background script, rather than between different parts of the background script. chrome.runtime.connect method to establish a long-lived connection between your content script and your background script. This will ensure that your service worker stays alive for as long as the connection is active. chrome.runtime.connect to establish a long-lived connection:chrome.tabs API to communicate between tabs. One way to pass data between tabs is to use the sendMessage method to send a message from one tab to another. Here's an example:localStorage API to store data in one tab and retrieve it in another tab. However, keep in mind that this approach has some limitations, such as the amount of data that can be stored and the fact that the data is not automatically updated when it changes in another tab.chrome.storage API to retrieve the stored data and then update the matches property accordingly. Here's an example code snippet:myData using the chrome.storage API. Let me know if you have any further questions or if there's anything else I can help you with!MAX_WRITE_OPERATIONS_PER_MINUTE error occurs when you exceed the maximum number of write operations per minute allowed by the Chrome storage API. This error can occur even if you are not explicitly writing to the storage, as some actions such as setting state in React can trigger storage writes.chrome.storage.onChanged event to track changes to the storage and see which parts of your code are triggering the writes. You can add a listener for this event and log the changes to the console to help identify the source of the issue.chrome.storage API to store and retrieve data. To dynamically match a URL property based on storage configuration, you can first retrieve the configuration data from storage using chrome.storage.sync.get(). Once you have the configuration data, you can use it to construct a regular expression that matches the desired URLs. http:// or https:// and contains one of the domains specified in the configuration data.calculateMatches function on the PlasmoCSConfig object.calculateMatches function:PlasmoCSConfig, and then passing in an input string to the calculateMatches function. The function will return an array of matches that were found in the input string.getRandomValues function is not available in the crypto object. This function is used to generate cryptographically secure random numbers, and is required for the randomBytes function to work properly.crypto object is imported from the crypto_1 module. This module is not a standard part of the browser environment, and is typically used in Node.js environments. window.crypto object instead of crypto_1.crypto. This object is available in modern browsers and provides the same functionality as the crypto module in Node.js.randomBytes function that uses window.crypto:randomBytes function to generate secure random numbers in your browser extension.PlasmoCSConfig class, but it's not working because PlasmoCSConfig is a type, not a constructor. To create a new instance of the PlasmoCSConfig class, you'll need to use the new keyword with the constructor function.PlasmoCSConfig object and calculate the matches property when the tsx file is loaded:PlasmoCSConfig class from the plasmo package and create a new instance of it with our custom properties. We then add an event listener to the DOMContentLoaded event, which fires when the tsx file is loaded. In the event listener, we call a function to calculate the matches property and set it on our custom config object.export keyword within the promise's callback function. Here's an example:myConfig object within the promise's callback function. We then use the export keyword to export the myConfig object. Finally, we resolve the promise and log a message to the console to confirm that the object was exported.chrome.contentScripts.register API. Here's an example:https://www.example.com/*. The js and css properties specify the files that should be injected into the page. The runAt property specifies when the script should be injected (in this case, at the end of the document). The allFrames property specifies whether the script should run in all frames of the page. Finally, the excludeGlobs property specifies any URL patterns that should be excluded from the content script.chrome.scripting.getRegisteredContentScripts function to retrieve information about the content scripts that have been registered for a particular extension. This can be useful if you need to dynamically modify or remove content scripts based on user preferences or other factors.chrome.scripting.getRegisteredContentScripts function to retrieve information about all the content scripts that have been registered for our extension. We're passing in an options object that specifies the extension ID (which we can get from chrome.runtime.id) and a callback function that will be called with an array of content script objects.js array), as well as the list of URL patterns that the script matches (which is stored in the matches array).chrome.storage.sync, you would use chrome.storage.local. chrome.runtime.onMessage event to listen for messages sent between the two scripts. When a message is received, you can then update the local storage accordingly. redux-persist to persist your Redux state, but you are encountering an error that says TypeError: Cannot read properties of undefined (reading 'local'). This error is usually caused by a misconfiguration of the storage option in your persistConfig.storage option is undefined, which means that redux-persist is trying to read the local property of an undefined object. This could happen if you forgot to import the storage library that you are using, or if you misspelled the name of the storage library.redux-persist-webextension-storage to persist your Redux state in a browser extension, make sure that you have installed the library and imported it correctly in your code. Here's an example of how you can configure redux-persist to use redux-persist-webextension-storage:storage from redux-persist-webextension-storage and use it as the storage option in our persistConfig. This should allow redux-persist to correctly store and retrieve your Redux state in the browser's storage.import statement, and will instead use the native ES module system of Chrome 91.import statement to a format that is compatible with Internet Explorer 11.Storage interface provided by @plasmohq/storage. Specifically, it is saying that the getAllKeys property is missing from the StorageInterface type, which is required by the Storage type.@plasmohq/storage to include the StorageInterface type explicitly. Here's an example:persistConfig object to use the StorageInterface type instead of the Storage type:localStorage as StorageInterface, you are telling TypeScript to treat it as if it has the getAllKeys property, even though it is not explicitly defined in the Storage type..modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}topleftUncaught Error: Extension context invalidated.
a?.disconnect(), a = globalThis.chrome.runtime.connect({chrome.runtime.connectchrome.runtime.connectchrome.runtime.connectchrome.runtime.connectchrome.runtime.connectchrome.runtime.connectchrome.runtime.connectchrome.runtime.connectchrome.runtime.onMessage.addListenerchrome.runtime.onMessage.addListenerglobalThis.chrome.runtime.connect// In your content script:
const port = chrome.runtime.connect({name: "my-port"});
// In your background script:
chrome.runtime.onConnect.addListener(function(port) {
console.assert(port.name == "my-port");
console.log("Connected to port:", port);
});chrome.tabsmatchesmatchesmatchesmatcheschrome.storage.sync.get('myData', (data) => {
const myData = data.myData;
const config = {
matches: myData.matches // or any other logic you want to use to set the matches property
};
// use the config object as needed
});myDataMAX_WRITE_OPERATIONS_PER_MINUTEchrome.storage.onChangedchrome.storage.sync.get()const config = await new Promise(resolve => {
chrome.storage.sync.get('config', resolve);
});
const domains = config.domains.join('|');
const regex = new RegExp(`^https?://(${domains})/`);http://https://calculateMatchescalculateMatchescalculateMatchesimport { PlasmoCSConfig } from 'plasmo';
const config = new PlasmoCSConfig();
const input = 'example input';
const matches = config.calculateMatches(input);
console.log(matches);exports.wrapConstructorWithOpts = wrapConstructorWithOpts;
/**
* Secure PRNG. Uses `globalThis.crypto` or node.js crypto module.
*/ function randomBytes(bytesLength = 32) {
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
throw new Error("crypto.getRandomValues must be defined");
}getRandomValuescryptocryptocryptorandomBytesrandomBytesrandomBytescrypto_1window.cryptowindow.cryptocrypto_1.cryptoconst config = new PlasmoCSConfig();PlasmoCSConfigconfigmatchesnewplasmoDOMContentLoaded'PlasmoCSConfig' only refers to a typeexport config objectexportexportconst myPromise = new Promise((resolve, reject) => {
const myConfig = {
option1: true,
option2: false
};
export { myConfig };
resolve();
});
myPromise.then(() => {
console.log('Exported myConfig object!');
});myConfigmyConfigchrome.contentScripts.registerchrome.contentScripts.register({
matches: ['https://www.example.com/*'],
js: [{file: 'content.js'}],
css: [{file: 'content.css'}],
runAt: 'document_end',
allFrames: true,
excludeGlobs: ['**/exclude/**']
});https://www.example.com/*jsjscssrunAtallFramesexcludeGlobschrome.scripting.getRegisteredContentScriptschrome.scripting.getRegisteredContentScriptschrome.scripting.getRegisteredContentScriptschrome.runtime.idchrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'update') {
chrome.storage.local.set({ data: message.data });
}
});chrome.storage.local.get('data', (result) => {
// Do something with the data
});
// Send a message to the background script to update the data
chrome.runtime.sendMessage({ type: 'update', data: newData });Error storing data TypeError: Cannot read properties of undefined (reading 'local')redux-persistredux-persistredux-persistredux-persistTypeError: Cannot read properties of undefined (reading 'local')storagestoragestoragestoragepersistConfigpersistConfigpersistConfiglocalredux-persist-webextension-storageredux-persist-webextension-storageredux-persist-webextension-storageimportimportProperty 'getAllKeys' is missing in type 'StorageInterface' but required in type 'Storage'import { combineReducers, configureStore } from "@reduxjs/toolkit"
import {
type TypedUseSelectorHook,
useDispatch,
useSelector
} from "react-redux"
import { syncStorage,localStorage } from "redux-persist-webextension-storage"
import {
FLUSH,
PAUSE,
PERSIST,
PURGE,
REGISTER,
REHYDRATE,
RESYNC,
persistReducer,
persistStore
} from "@plasmohq/redux-persist"
import { Storage } from "@plasmohq/storage"
import appReducer from "./app/appReducer"
const rootReducer = combineReducers({
app: appReducer
})
const persistConfig = {
key: "root",
version: 1,
storage: localStorage
}
const persistedReducer = persistReducer(persistConfig, rootReducer)StorageStorageStorageStorage@plasmohq/storage@plasmohq/storagegetAllKeysgetAllKeysStorageInterfaceStorageInterfaceStorageInterfaceStorageInterfaceimport { Storage, StorageInterface } from "@plasmohq/storage"const persistConfig = {
key: "root",
version: 1,
storage: localStorage as StorageInterface
}chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {data: "Hello from tab 1!"});
});chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
console.log(request.data); // logs "Hello from tab 1!"
});function randomBytes(bytesLength = 32) {
if (window.crypto && typeof window.crypto.getRandomValues === "function") {
return window.crypto.getRandomValues(new Uint8Array(bytesLength));
}
throw new Error("crypto.getRandomValues must be defined");
}import { PlasmoCSConfig } from 'plasmo';
// Define your custom config object
const myConfig = new PlasmoCSConfig({
// Set your custom properties here
// ...
});
// Calculate the matches property when the tsx file is loaded
document.addEventListener('DOMContentLoaded', () => {
const matches = calculateMatches();
myConfig.matches = matches;
});
// Function to calculate the matches property
function calculateMatches() {
// ...
}chrome.scripting.getRegisteredContentScripts({ extensionId: chrome.runtime.id }, (scripts) => {
console.log(`Found ${scripts.length} registered content scripts:`);
scripts.forEach((script) => {
console.log(`- ${script.js[0]} (${script.matches.join(', ')})`);
});
});import { persistReducer } from 'redux-persist';
import storage from 'redux-persist-webextension-storage';
const persistConfig = {
key: 'root',
storage,
};
const persistedReducer = persistReducer(persistConfig, rootReducer);import { someFunction } from './myModule.js';
chrome.runtime.onMessage.addListener((message) => {
someFunction(message);
});import { someFunction } from './myModule.js';
chrome.runtime.onMessage.addListener((message) => {
someFunction(message);
});