Closed TieWay59 closed 1 year ago
Could you post your manifest.json
?
Thank you for your fast reply @flosse. Here is my manifest file:
{
"name": "amazing-extension",
"version": "1.0",
"description": "amazing-extension",
"permissions": [],
"content_scripts": [
{
"matches": ["*://*.example.com/*"],
"js": ["amazing_extension.js", "run_wasm.js"]
}
],
"web_accessible_resources": [
{
"resources": ["amazing_extension_bg.wasm"],
"matches": ["*://*.example.com/*"]
}
],
"manifest_version": 3
}
And let me add more details on how to reproduce it.
cargo generate --git https://github.com/Mubelotix/wasm-extension-template --name amazing-extension
build.sh
, which I will run it by sh build.sh --manifest-version=3
because google chrome won't accept manifest2 in latest version.web-extensions = "0.3.0"
in cargo.tomlsrc\lib.rs -- pub async fn main()
, where I only introduced the use of use web_extensions::history::{search, Query};
sh build.sh --manifest-version=3
example.com
and see the console log print the results.It's strange that, if I only print the web_extensions::history::Query
instance, the result will be correct. But it seems the search function is just not found.
I hope this would help.
Here are the contents of the console log, it shows the query object is printed out correctly. But it can't find the history search attribute.
amazing_extension.js:313 Query {
text: "Query",
end_time: Some(
1669120728435,
),
max_results: Some(
3,
),
start_time: Some(
1669117128435,
),
}
amazing_extension.js:279 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'search')
at imports.wbg.__wbg_search_5602fc53d1278731 (amazing_extension.js:279:36)
at amazing_extension_bg.wasm:0x678f
at amazing_extension_bg.wasm:0x13d16
at amazing_extension_bg.wasm:0xea07
at amazing_extension_bg.wasm:0x170e0
at __wbg_adapter_18 (amazing_extension.js:210:10)
at real (amazing_extension.js:195:20)
try to add "history"
to the permissions.
@flosse It still prints the same error message. But I didn't think about the manifest before, I'll investigate it. If you get any more ideas please let me know, this problem has bothered me for a day.
Oh, after searching in developer.chrome.com, I think I found my answer.
According to https://developer.chrome.com/docs/extensions/mv3/content_scripts/#capabilities, it was said content scripts are unable to access other APIs directly(including history I guess).
I'll make some changes in the template project tomorrow, and maybe use this API in the background.
Sorry for the unrelated issue here, this is caused by my lacking of extension knowledge. I'll close it myself after I test my approach.
Hi, I'm trying to get into this crate and make some web extension demos. I found that
web_extensions::history::search
not working as I expected and threw an error of properties of undefined. I did my investigation for a day, but I‘m new to both wasm&web-extension so I still have not solved this problem. More details will show below:My main logic is as below, it's very simple:
The search function is an alias of
web_extensions::history::search
.In the generated js file, the error line is:
I see this means the object taken from the heap does not contain the
search
property.Version Info
Google Chrome: 107.0.5304.107 wasm-bindgen = "0.2.83" js-sys = "0.3" wasm-bindgen-futures = "0.4" console_error_panic_hook = "0.1.6" web-extensions = "0.3.0"
I'm not sure any other information is helpful if provided, let me know if you need more to locate the error.