Skip to content
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

When my plugin opens a local html page, it can't find the js file in the same directory as the page? #43

Closed
14790897 opened this issue Nov 2, 2023 · 7 comments

Comments

@14790897
Copy link

14790897 commented Nov 2, 2023

No description provided.

@mubaidr
Copy link
Owner

mubaidr commented Nov 2, 2023

Opening local html page means install/ update page?
Can you please share a reproduceable repo. I will be able to help quickly. Thanks

@14790897
Copy link
Author

14790897 commented Nov 2, 2023

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';">

  <title>Word Cloud</title>
</head>
<body>
  <div id="app"></div>
  <script src="script.js"></script>
</body>
</html>

@14790897
Copy link
Author

14790897 commented Nov 2, 2023

It can't find script.js in the same directory.

@14790897
Copy link
Author

14790897 commented Nov 2, 2023

 const url = chrome.runtime.getURL('src/components/wordcloud.html');
  console.log('URL:', url); 
  chrome.tabs.create({ url: url }, (tab) => {
    if (chrome.runtime.lastError) {
      console.error(chrome.runtime.lastError);  
    } else {
      console.log('Tab created:', tab);  
    }
  });

@mubaidr
Copy link
Owner

mubaidr commented Nov 2, 2023

You should try using relative path for script, i.e. ./script.js

@14790897
Copy link
Author

14790897 commented Nov 3, 2023

I was wrong before, the error is not about not finding the file but about the following error
image

@mubaidr
Copy link
Owner

mubaidr commented Nov 4, 2023

You are trying to use import statements inside static html page and scripts, which are not supported. Either add bundler (vite) processing for install and upgrade page or use simple scripts.

@mubaidr mubaidr closed this as completed Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants